BxDolCacheXCache.php 1.9 KB

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