26 #require_once 'Zend/Cache/Backend.php'; 31 #require_once 'Zend/Cache/Backend/Interface.php'; 63 $licenseInfo = accelerator_license_info();
66 $accConf = accelerator_get_configuration();
67 if (@!$accConf[
'output_cache_licensed']) {
70 if (@!$accConf[
'output_cache_enabled']) {
71 Zend_Cache::throwException(
'The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
76 parent:: __construct($options); 86 public function load($id, $doNotTestCacheValidity = false) 88 // doNotTestCacheValidity implemented by giving zero lifetime to the cache 89 if ($doNotTestCacheValidity) { 92 $lifetime = $this->_directives['lifetime
']; 94 $res = output_cache_get($id, $lifetime); 109 public function test($id) 111 $result = output_cache_get($id, $this->_directives['lifetime
']); 130 public function save($data, $id, $tags = array(), $specificLifetime = false) 132 if (!($specificLifetime === false)) { 133 $this->_log("Zend_Cache_Backend_ZendPlatform::save() : non false specifc lifetime is unsuported for this backend"); 136 $lifetime = $this->_directives['lifetime
']; 137 $result1 = output_cache_put($id, array($data, time())); 138 $result2 = (count($tags) == 0); 140 foreach ($tags as $tag) { 141 $tagid = self::TAGS_PREFIX.$tag; 142 $old_tags = output_cache_get($tagid, $lifetime); 143 if ($old_tags === false) { 146 $old_tags[$id] = $id; 147 output_cache_remove_key($tagid); 148 $result2 = output_cache_put($tagid, $old_tags); 151 return $result1 && $result2; 161 public function remove($id) 163 return output_cache_remove_key($id); 185 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) 188 case Zend_Cache::CLEANING_MODE_ALL: 189 case Zend_Cache::CLEANING_MODE_OLD: 190 $cache_dir = ini_get('zend_accelerator.output_cache_dir
'); 194 $cache_dir .= '/.php_cache_api/
'; 195 return $this->_clean($cache_dir, $mode); 197 case Zend_Cache::CLEANING_MODE_MATCHING_TAG: 199 foreach ($tags as $tag) { 200 $next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime
']); 202 $idlist = array_intersect_assoc($idlist, $next_idlist); 204 $idlist = $next_idlist; 206 if (count($idlist) == 0) { 207 // if ID list is already empty - we may skip checking other IDs 213 foreach ($idlist as $id) { 214 output_cache_remove_key($id); 219 case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: 220 $this->_log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend"); 223 case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: 225 foreach ($tags as $tag) { 226 $next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime
']); 228 $idlist = array_merge_recursive($idlist, $next_idlist); 230 $idlist = $next_idlist; 232 if (count($idlist) == 0) { 233 // if ID list is already empty - we may skip checking other IDs 239 foreach ($idlist as $id) { 240 output_cache_remove_key($id); 246 Zend_Cache::throwException('Invalid mode
for clean() method
'); 260 private function _clean($dir, $mode) 267 while (false !== ($file = $d->read())) { 268 if ($file == '.
' || $file == '..
') { 271 $file = $d->path . $file; 273 $result = ($this->_clean($file .'/
', $mode)) && ($result); 275 if ($mode == Zend_Cache::CLEANING_MODE_ALL) { 276 $result = ($this->_remove($file)) && ($result); 277 } else if ($mode == Zend_Cache::CLEANING_MODE_OLD) { 278 // Files older than lifetime get deleted from cache 279 if ($this->_directives['lifetime
'] !== null) { 280 if ((time() - @filemtime($file)) > $this->_directives['lifetime
']) { 281 $result = ($this->_remove($file)) && ($result); 300 private function _remove($file) 302 if (!@unlink($file)) { 303 # If we can't
remove the file (because of locks or any problem), we will touch
304 # the file to invalidate it
305 $this->
_log(
"Zend_Cache_Backend_ZendPlatform::_remove() : we can't remove $file => we are going to try to invalidate it");
306 if ($this->_directives[
'lifetime'] ===
null) {
309 if (!file_exists($file)) {
312 return @touch($file,
time() - 2*abs($this->_directives[
'lifetime']));
_log($message, $priority=4)
static throwException($msg, Exception $e=null)