/drivers/XCache_xcache.php

https://bitbucket.org/xperez/xcache · PHP · 197 lines · 86 code · 41 blank · 70 comment · 22 complexity · 0107a6b88bfeade6e175bdf6947b6aa9 MD5 · raw file

  1. <?php
  2. /**
  3. * XCache XCache Caching Class
  4. *
  5. * @package XCache
  6. * @subpackage Libraries
  7. * @category Xcache
  8. * @author XPerez
  9. * @link
  10. */
  11. class XCache_xcache extends XCache {
  12. private $_instance;
  13. public function __construct() {
  14. }
  15. /**
  16. * Get
  17. *
  18. * Since this is the dummy class, it's always going to return FALSE.
  19. *
  20. * @param string
  21. * @return Boolean FALSE
  22. */
  23. public function readCache($type,$name,$ID,$onlyCheck=FALSE)
  24. {
  25. $this->getInstance();
  26. $originalID = $ID;
  27. if (isset($_POST) && count($_POST)>0)
  28. $ID = $ID.md5(serialize($_POST));
  29. self::logMessage('debug', "Reading APC $type - $name - $ID.");
  30. $item_expiration = $this->getCacheItemExpiration($type,$name,$originalID);
  31. if (is_array($item_expiration))
  32. {
  33. $item_properties = $item_expiration;
  34. $name .= '-'.$item_properties[0];
  35. $item_expiration = $item_properties[1];
  36. }
  37. if ($item_expiration == FALSE)
  38. {
  39. $item_expiration = $this->getCacheConfigItem('default',$type);
  40. if ($item_expiration == FALSE)
  41. return FALSE;
  42. }
  43. $cache=xcache_get($type.'-'.$name.'-'.$ID);
  44. if ($cache == FALSE)
  45. return FALSE;
  46. if (function_exists('profiler_log')) profiler_log('CACHE','APC Read OK: '.$type.'/'.$name.'/'.$ID);
  47. if ($cache && $onlyCheck)
  48. return TRUE;
  49. return unserialize($cache);
  50. }
  51. // ------------------------------------------------------------------------
  52. /**
  53. * Cache Save
  54. *
  55. * @param string Unique Key
  56. * @param mixed Data to store
  57. * @param int Length of time (in seconds) to cache the data
  58. *
  59. * @return boolean TRUE, Simulating success
  60. */
  61. public function writeCache($type,$name,$ID,$output,$depID="")
  62. {
  63. $originalID = $ID;
  64. //if (function_exists('profiler_log')) profiler_log('CACHE','Memcache Write init : '.$type.'/'.$name.'/'.$ID);
  65. $item_expiration = $this->getCacheItemExpiration($type,$name,$originalID);
  66. if (is_array($item_expiration))
  67. {
  68. $item_properties = $item_expiration;
  69. $name .= '-'.$item_properties[0];
  70. $item_expiration = $item_properties[1];
  71. }
  72. if ($item_expiration == FALSE)
  73. {
  74. $item_expiration = $this->getCacheConfigItem('default',$type);
  75. if ($item_expiration == FALSE)
  76. return FALSE;
  77. }
  78. xcache_set($type.'-'.$name.'-'.$ID, serialize($output), $item_expiration);
  79. if (function_exists('profiler_log')) profiler_log('CACHE','APC Write OK: '.$type.'/'.$name.'/'.$ID);
  80. return TRUE;
  81. }
  82. // ------------------------------------------------------------------------
  83. /**
  84. * Delete from Cache
  85. *
  86. * @param mixed unique identifier of the item in the cache
  87. * @param boolean TRUE, simulating success
  88. */
  89. public function deleteCache($type,$name,$ID)
  90. {
  91. $originalID = $ID;
  92. if (isset($_POST) && count($_POST)>0)
  93. $ID = $ID.md5(serialize($_POST));
  94. return xcache_unset($type.'-'.$name.'-'.$ID);
  95. }
  96. // ------------------------------------------------------------------------
  97. /**
  98. * Clean the cache
  99. *
  100. * @return boolean TRUE, simulating success
  101. */
  102. public function cleanCache()
  103. {
  104. return xcache_clear_cache();
  105. }
  106. // ------------------------------------------------------------------------
  107. /**
  108. * Cache Info
  109. *
  110. * @param string user/filehits
  111. * @return boolean FALSE
  112. */
  113. public function getCacheInfo($type = NULL)
  114. {
  115. return FALSE;
  116. }
  117. // ------------------------------------------------------------------------
  118. /**
  119. * Get Cache Metadata
  120. *
  121. * @param mixed key to get cache metadata on
  122. * @return boolean FALSE
  123. */
  124. public function getCacheMetadata($id)
  125. {
  126. return FALSE;
  127. }
  128. // ------------------------------------------------------------------------
  129. /**
  130. * Is this caching driver supported on the system?
  131. * Of course this one is.
  132. *
  133. * @return TRUE;
  134. */
  135. public function isSupported()
  136. {
  137. if ( ! extension_loaded('xcache') OR ini_get('xcache.size') == "0")
  138. {
  139. self::logMessage('error', 'The XCACHE PHP extension must be loaded to use XCache Cache.');
  140. return FALSE;
  141. }
  142. return TRUE;
  143. }
  144. // ------------------------------------------------------------------------
  145. /**
  146. * getInstance
  147. *
  148. */
  149. private function getInstance()
  150. {
  151. return $this;
  152. }
  153. }
  154. // End Class
  155. /* End of file Cache_memcache.php */
  156. /* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */