Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Eaccelerator.php
Go to the documentation of this file.
1 <?php
8 
10 {
15  'Magento\Framework\Cache\Backend\Eaccelerator::clean() : tags are unsupported by the Eaccelerator backend';
16 
18  'Magento\Framework\Cache\Backend\Eaccelerator::save() : tags are unsupported by the Eaccelerator backend';
19 
26  public function __construct(array $options = [])
27  {
28  if (!extension_loaded('eaccelerator')) {
29  \Zend_Cache::throwException('The eaccelerator extension must be loaded for using this backend !');
30  }
31  parent::__construct($options);
32  }
33 
44  public function load($id, $doNotTestCacheValidity = false)
45  {
46  $tmp = eaccelerator_get($id);
47  if (is_array($tmp)) {
48  return $tmp[0];
49  }
50  return false;
51  }
52 
59  public function test($id)
60  {
61  $tmp = eaccelerator_get($id);
62  if (is_array($tmp)) {
63  return $tmp[1];
64  }
65  return false;
66  }
67 
80  public function save($data, $id, $tags = [], $specificLifetime = false)
81  {
82  $lifetime = $this->getLifetime($specificLifetime);
83  $result = eaccelerator_put($id, [$data, time(), $lifetime], $lifetime);
84  if (count($tags) > 0) {
85  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
86  }
87  return $result;
88  }
89 
96  public function remove($id)
97  {
98  return eaccelerator_rm($id);
99  }
100 
117  public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
118  {
119  switch ($mode) {
120  case \Zend_Cache::CLEANING_MODE_ALL:
121  return eaccelerator_clean();
122  break;
123  case \Zend_Cache::CLEANING_MODE_OLD:
124  $this->_log(
125  "Magento\Framework\Cache\Backend\Eaccelerator::clean() : ".
126  "CLEANING_MODE_OLD is unsupported by the Eaccelerator backend"
127  );
128  break;
129  case \Zend_Cache::CLEANING_MODE_MATCHING_TAG:
130  case \Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
131  case \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
132  $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_EACCELERATOR_BACKEND);
133  break;
134  default:
135  \Zend_Cache::throwException('Invalid mode for clean() method');
136  break;
137  }
138  }
139 
146  public function getFillingPercentage()
147  {
148  $mem = eaccelerator_info();
149  $memSize = $mem['memorySize'];
150  $memAvailable = $mem['memoryAvailable'];
151  $memUsed = $memSize - $memAvailable;
152  if ($memSize == 0) {
153  \Zend_Cache::throwException('can\'t get eaccelerator memory size');
154  }
155  if ($memUsed > $memSize) {
156  return 100;
157  }
158  return (int)(100. * ($memUsed / $memSize));
159  }
160 
166  public function getTags()
167  {
168  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
169  return [];
170  }
171 
181  public function getIdsMatchingTags($tags = [])
182  {
183  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
184  return [];
185  }
186 
196  public function getIdsNotMatchingTags($tags = [])
197  {
198  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
199  return [];
200  }
201 
211  public function getIdsMatchingAnyTags($tags = [])
212  {
213  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
214  return [];
215  }
216 
223  public function getIds()
224  {
225  $res = [];
226  $array = eaccelerator_list_keys();
227  foreach ($array as $key => $info) {
228  $res[] = $key;
229  }
230  return $res;
231  }
232 
245  public function getMetadatas($id)
246  {
247  $tmp = eaccelerator_get($id);
248  if (is_array($tmp)) {
249  $data = $tmp[0];
250  $mtime = $tmp[1];
251  if (!isset($tmp[2])) {
252  // because this record is only with 1.7 release
253  // if old cache records are still there...
254  return false;
255  }
256  $lifetime = $tmp[2];
257  return ['expire' => $mtime + $lifetime, 'tags' => [], 'mtime' => $mtime];
258  }
259  return false;
260  }
261 
269  public function touch($id, $extraLifetime)
270  {
271  $tmp = eaccelerator_get($id);
272  if (is_array($tmp)) {
273  $data = $tmp[0];
274  $mtime = $tmp[1];
275  if (!isset($tmp[2])) {
276  // because this record is only with 1.7 release
277  // if old cache records are still there...
278  return false;
279  }
280  $lifetime = $tmp[2];
281  $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
282  if ($newLifetime <= 0) {
283  return false;
284  }
285  eaccelerator_put($id, [$data, time(), $newLifetime], $newLifetime);
286  return true;
287  }
288  return false;
289  }
290 
305  public function getCapabilities()
306  {
307  return [
308  'automatic_cleaning' => false,
309  'tags' => false,
310  'expired_read' => false,
311  'priority' => false,
312  'infinite_lifetime' => false,
313  'get_list' => true
314  ];
315  }
316 }
load($id, $doNotTestCacheValidity=false)
$id
Definition: fieldset.phtml:14
clean($mode=\Zend_Cache::CLEANING_MODE_ALL, $tags=[])
save($data, $id, $tags=[], $specificLifetime=false)
_log($message, $priority=4)
Definition: Backend.php:273
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
const CLEANING_MODE_ALL
Definition: Cache.php:72
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
getLifetime($specificLifetime)
Definition: Backend.php:143