00001 <?php 00025 require_once 'Zend/Cache/Backend/Interface.php'; 00026 00028 require_once 'Zend/Cache/Backend.php'; 00029 00030 00037 abstract class Zend_Cache_Backend_ZendServer extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface 00038 { 00047 protected $_options = array( 00048 'namespace' => 'zendframework' 00049 ); 00050 00059 abstract protected function _store($data, $id, $timeToLive); 00060 00067 abstract protected function _fetch($id); 00068 00074 abstract protected function _unset($id); 00075 00079 abstract protected function _clear(); 00080 00088 public function load($id, $doNotTestCacheValidity = false) 00089 { 00090 $tmp = $this->_fetch($id); 00091 if ($tmp !== null) { 00092 return $tmp; 00093 } 00094 return false; 00095 } 00096 00104 public function test($id) 00105 { 00106 $tmp = $this->_fetch('internal-metadatas---' . $id); 00107 if ($tmp !== false) { 00108 if (!is_array($tmp) || !isset($tmp['mtime'])) { 00109 Zend_Cache::throwException('Cache metadata for \'' . $id . '\' id is corrupted' ); 00110 } 00111 return $tmp['mtime']; 00112 } 00113 return false; 00114 } 00115 00121 private function _expireTime($lifetime) 00122 { 00123 if ($lifetime === null) { 00124 return 9999999999; 00125 } 00126 return time() + $lifetime; 00127 } 00128 00141 public function save($data, $id, $tags = array(), $specificLifetime = false) 00142 { 00143 $lifetime = $this->getLifetime($specificLifetime); 00144 $metadatas = array( 00145 'mtime' => time(), 00146 'expire' => $this->_expireTime($lifetime), 00147 ); 00148 00149 if (count($tags) > 0) { 00150 $this->_log('Zend_Cache_Backend_ZendServer::save() : tags are unsupported by the ZendServer backends'); 00151 } 00152 00153 return $this->_store($data, $id, $lifetime) && 00154 $this->_store($metadatas, 'internal-metadatas---' . $id, $lifetime); 00155 } 00156 00163 public function remove($id) 00164 { 00165 $result1 = $this->_unset($id); 00166 $result2 = $this->_unset('internal-metadatas---' . $id); 00167 00168 return $result1 && $result2; 00169 } 00170 00186 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) 00187 { 00188 switch ($mode) { 00189 case Zend_Cache::CLEANING_MODE_ALL: 00190 $this->_clear(); 00191 return true; 00192 break; 00193 case Zend_Cache::CLEANING_MODE_OLD: 00194 $this->_log("Zend_Cache_Backend_ZendServer::clean() : CLEANING_MODE_OLD is unsupported by the Zend Server backends."); 00195 break; 00196 case Zend_Cache::CLEANING_MODE_MATCHING_TAG: 00197 case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: 00198 case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: 00199 $this->_clear(); 00200 $this->_log('Zend_Cache_Backend_ZendServer::clean() : tags are unsupported by the Zend Server backends.'); 00201 break; 00202 default: 00203 Zend_Cache::throwException('Invalid mode for clean() method'); 00204 break; 00205 } 00206 } 00207 }