Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WinCache.php
Go to the documentation of this file.
1 <?php
27 #require_once 'Zend/Cache/Backend/ExtendedInterface.php';
28 
32 #require_once 'Zend/Cache/Backend.php';
33 
34 
42 {
46  const TAGS_UNSUPPORTED_BY_CLEAN_OF_WINCACHE_BACKEND = 'Zend_Cache_Backend_WinCache::clean() : tags are unsupported by the WinCache backend';
47  const TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND = 'Zend_Cache_Backend_WinCache::save() : tags are unsupported by the WinCache backend';
48 
56  public function __construct(array $options = array())
57  {
58  if (!extension_loaded('wincache')) {
59  Zend_Cache::throwException('The wincache extension must be loaded for using this backend !');
60  }
61  parent::__construct($options);
62  }
63 
73  public function load($id, $doNotTestCacheValidity = false)
74  {
75  $tmp = wincache_ucache_get($id);
76  if (is_array($tmp)) {
77  return $tmp[0];
78  }
79  return false;
80  }
81 
88  public function test($id)
89  {
90  $tmp = wincache_ucache_get($id);
91  if (is_array($tmp)) {
92  return $tmp[1];
93  }
94  return false;
95  }
96 
109  public function save($data, $id, $tags = array(), $specificLifetime = false)
110  {
111  $lifetime = $this->getLifetime($specificLifetime);
112  $result = wincache_ucache_set($id, array($data, time(), $lifetime), $lifetime);
113  if (count($tags) > 0) {
114  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
115  }
116  return $result;
117  }
118 
125  public function remove($id)
126  {
127  return wincache_ucache_delete($id);
128  }
129 
145  public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
146  {
147  switch ($mode) {
149  return wincache_ucache_clear();
150  break;
152  $this->_log("Zend_Cache_Backend_WinCache::clean() : CLEANING_MODE_OLD is unsupported by the WinCache backend");
153  break;
157  $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_WINCACHE_BACKEND);
158  break;
159  default:
160  Zend_Cache::throwException('Invalid mode for clean() method');
161  break;
162  }
163  }
164 
174  {
175  return false;
176  }
177 
184  public function getFillingPercentage()
185  {
186  $mem = wincache_ucache_meminfo();
187  $memSize = $mem['memory_total'];
188  $memUsed = $memSize - $mem['memory_free'];
189  if ($memSize == 0) {
190  Zend_Cache::throwException('can\'t get WinCache memory size');
191  }
192  if ($memUsed > $memSize) {
193  return 100;
194  }
195  return ((int) (100. * ($memUsed / $memSize)));
196  }
197 
203  public function getTags()
204  {
205  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
206  return array();
207  }
208 
217  public function getIdsMatchingTags($tags = array())
218  {
219  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
220  return array();
221  }
222 
231  public function getIdsNotMatchingTags($tags = array())
232  {
233  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
234  return array();
235  }
236 
245  public function getIdsMatchingAnyTags($tags = array())
246  {
247  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND);
248  return array();
249  }
250 
256  public function getIds()
257  {
258  $res = array();
259  $array = wincache_ucache_info();
260  $records = $array['ucache_entries'];
261  foreach ($records as $record) {
262  $res[] = $record['key_name'];
263  }
264  return $res;
265  }
266 
278  public function getMetadatas($id)
279  {
280  $tmp = wincache_ucache_get($id);
281  if (is_array($tmp)) {
282  $data = $tmp[0];
283  $mtime = $tmp[1];
284  if (!isset($tmp[2])) {
285  return false;
286  }
287  $lifetime = $tmp[2];
288  return array(
289  'expire' => $mtime + $lifetime,
290  'tags' => array(),
291  'mtime' => $mtime
292  );
293  }
294  return false;
295  }
296 
304  public function touch($id, $extraLifetime)
305  {
306  $tmp = wincache_ucache_get($id);
307  if (is_array($tmp)) {
308  $data = $tmp[0];
309  $mtime = $tmp[1];
310  if (!isset($tmp[2])) {
311  return false;
312  }
313  $lifetime = $tmp[2];
314  $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
315  if ($newLifetime <=0) {
316  return false;
317  }
318  return wincache_ucache_set($id, array($data, time(), $newLifetime), $newLifetime);
319  }
320  return false;
321  }
322 
337  public function getCapabilities()
338  {
339  return array(
340  'automatic_cleaning' => false,
341  'tags' => false,
342  'expired_read' => false,
343  'priority' => false,
344  'infinite_lifetime' => false,
345  'get_list' => true
346  );
347  }
348 
349 }
getIdsMatchingAnyTags($tags=array())
Definition: WinCache.php:245
$id
Definition: fieldset.phtml:14
getIdsNotMatchingTags($tags=array())
Definition: WinCache.php:231
getIdsMatchingTags($tags=array())
Definition: WinCache.php:217
const CLEANING_MODE_OLD
Definition: Cache.php:73
_log($message, $priority=4)
Definition: Backend.php:273
__construct(array $options=array())
Definition: WinCache.php:56
const CLEANING_MODE_NOT_MATCHING_TAG
Definition: Cache.php:75
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
clean($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
Definition: WinCache.php:145
const CLEANING_MODE_ALL
Definition: Cache.php:72
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
const TAGS_UNSUPPORTED_BY_CLEAN_OF_WINCACHE_BACKEND
Definition: WinCache.php:46
const CLEANING_MODE_MATCHING_ANY_TAG
Definition: Cache.php:76
save($data, $id, $tags=array(), $specificLifetime=false)
Definition: WinCache.php:109
const CLEANING_MODE_MATCHING_TAG
Definition: Cache.php:74
const TAGS_UNSUPPORTED_BY_SAVE_OF_WINCACHE_BACKEND
Definition: WinCache.php:47
getLifetime($specificLifetime)
Definition: Backend.php:143
load($id, $doNotTestCacheValidity=false)
Definition: WinCache.php:73
touch($id, $extraLifetime)
Definition: WinCache.php:304