BxDolCacheXCache.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolCache');
  10. class BxDolCacheXCache extends BxDolCache
  11. {
  12. protected $iTTL = 3600;
  13. /**
  14. * Get data from shared memory cache
  15. *
  16. * @param string $sKey - file name
  17. * @param int $iTTL - time to live
  18. * @return the data is got from cache.
  19. */
  20. function getData($sKey, $iTTL = false)
  21. {
  22. if (!xcache_isset($sKey))
  23. return null;
  24. return xcache_get($sKey);
  25. }
  26. /**
  27. * Save data in shared memory cache
  28. *
  29. * @param string $sKey - file name
  30. * @param mixed $mixedData - the data to be cached in the file
  31. * @param int $iTTL - time to live
  32. * @return boolean result of operation.
  33. */
  34. function setData($sKey, $mixedData, $iTTL = false)
  35. {
  36. $bResult = xcache_set($sKey, $mixedData, false === $iTTL ? $this->iTTL : $iTTL);
  37. return $bResult;
  38. }
  39. /**
  40. * Delete cache from shared memory
  41. *
  42. * @param string $sKey - file name
  43. * @return result of the operation
  44. */
  45. function delData($sKey)
  46. {
  47. if (!xcache_isset($sKey))
  48. return true;
  49. return xcache_unset($sKey);
  50. }
  51. /**
  52. * Check if xcache functions are available
  53. * @return boolean
  54. */
  55. function isAvailable()
  56. {
  57. return extension_loaded('xcache');
  58. }
  59. /**
  60. * Check if xcache extension is loaded
  61. * @return boolean
  62. */
  63. function isInstalled()
  64. {
  65. return extension_loaded('xcache');
  66. }
  67. /**
  68. * remove all data from cache by key prefix
  69. * @return true on success
  70. */
  71. function removeAllByPrefix ($s)
  72. {
  73. return xcache_unset_by_prefix ($s);
  74. }
  75. }
  76. /** @} */