Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ZendServer.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Cache/Backend/Interface.php';
26 
28 #require_once 'Zend/Cache/Backend.php';
29 
30 
38 {
47  protected $_options = array(
48  'namespace' => 'zendframework'
49  );
50 
59  abstract protected function _store($data, $id, $timeToLive);
60 
67  abstract protected function _fetch($id);
68 
74  abstract protected function _unset($id);
75 
79  abstract protected function _clear();
80 
88  public function load($id, $doNotTestCacheValidity = false)
89  {
90  $tmp = $this->_fetch($id);
91  if ($tmp !== null) {
92  return $tmp;
93  }
94  return false;
95  }
96 
104  public function test($id)
105  {
106  $tmp = $this->_fetch('internal-metadatas---' . $id);
107  if ($tmp !== false) {
108  if (!is_array($tmp) || !isset($tmp['mtime'])) {
109  Zend_Cache::throwException('Cache metadata for \'' . $id . '\' id is corrupted' );
110  }
111  return $tmp['mtime'];
112  }
113  return false;
114  }
115 
121  private function _expireTime($lifetime)
122  {
123  if ($lifetime === null) {
124  return 9999999999;
125  }
126  return time() + $lifetime;
127  }
128 
141  public function save($data, $id, $tags = array(), $specificLifetime = false)
142  {
143  $lifetime = $this->getLifetime($specificLifetime);
144  $metadatas = array(
145  'mtime' => time(),
146  'expire' => $this->_expireTime($lifetime),
147  );
148 
149  if (count($tags) > 0) {
150  $this->_log('Zend_Cache_Backend_ZendServer::save() : tags are unsupported by the ZendServer backends');
151  }
152 
153  return $this->_store($data, $id, $lifetime) &&
154  $this->_store($metadatas, 'internal-metadatas---' . $id, $lifetime);
155  }
156 
163  public function remove($id)
164  {
165  $result1 = $this->_unset($id);
166  $result2 = $this->_unset('internal-metadatas---' . $id);
167 
168  return $result1 && $result2;
169  }
170 
186  public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
187  {
188  switch ($mode) {
189  case Zend_Cache::CLEANING_MODE_ALL:
190  $this->_clear();
191  return true;
192  break;
193  case Zend_Cache::CLEANING_MODE_OLD:
194  $this->_log("Zend_Cache_Backend_ZendServer::clean() : CLEANING_MODE_OLD is unsupported by the Zend Server backends.");
195  break;
196  case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
197  case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
198  case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
199  $this->_clear();
200  $this->_log('Zend_Cache_Backend_ZendServer::clean() : tags are unsupported by the Zend Server backends.');
201  break;
202  default:
203  Zend_Cache::throwException('Invalid mode for clean() method');
204  break;
205  }
206  }
207 }
save($data, $id, $tags=array(), $specificLifetime=false)
Definition: ZendServer.php:141
$id
Definition: fieldset.phtml:14
clean($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
Definition: ZendServer.php:186
load($id, $doNotTestCacheValidity=false)
Definition: ZendServer.php:88
_store($data, $id, $timeToLive)
static throwException($msg, Exception $e=null)
Definition: Cache.php:205