BxDolCacheXCache.php 1.8 KB

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