Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
Eaccelerator Class Reference
Inheritance diagram for Eaccelerator:
Zend_Cache_Backend Zend_Cache_Backend_ExtendedInterface Zend_Cache_Backend_Interface

Public Member Functions

 __construct (array $options=[])
 
 load ($id, $doNotTestCacheValidity=false)
 
 test ($id)
 
 save ($data, $id, $tags=[], $specificLifetime=false)
 
 remove ($id)
 
 clean ($mode=\Zend_Cache::CLEANING_MODE_ALL, $tags=[])
 
 getFillingPercentage ()
 
 getTags ()
 
 getIdsMatchingTags ($tags=[])
 
 getIdsNotMatchingTags ($tags=[])
 
 getIdsMatchingAnyTags ($tags=[])
 
 getIds ()
 
 getMetadatas ($id)
 
 touch ($id, $extraLifetime)
 
 getCapabilities ()
 
- Public Member Functions inherited from Zend_Cache_Backend
 __construct (array $options=array())
 
 setDirectives ($directives)
 
 setOption ($name, $value)
 
 getOption ($name)
 
 getLifetime ($specificLifetime)
 
 isAutomaticCleaningAvailable ()
 
 getTmpDir ()
 
- Public Member Functions inherited from Zend_Cache_Backend_Interface
 setDirectives ($directives)
 

Data Fields

const TAGS_UNSUPPORTED_BY_CLEAN_OF_EACCELERATOR_BACKEND
 
const TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND
 

Additional Inherited Members

- Protected Member Functions inherited from Zend_Cache_Backend
 _isGoodTmpDir ($dir)
 
 _loggerSanity ()
 
 _log ($message, $priority=4)
 
- Protected Attributes inherited from Zend_Cache_Backend
 $_directives
 
 $_options = array()
 

Detailed Description

Definition at line 9 of file Eaccelerator.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = [])

Constructor

Parameters
array$optionsassociative array of options
Exceptions

Definition at line 26 of file Eaccelerator.php.

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  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

Member Function Documentation

◆ clean()

clean (   $mode = \Zend_Cache::CLEANING_MODE_ALL,
  $tags = [] 
)

Clean some cache records

Available modes are : 'all' (default) => remove all cache entries ($tags is not used) 'old' => unsupported 'matchingTag' => unsupported 'notMatchingTag' => unsupported 'matchingAnyTag' => unsupported

Parameters
string$modeclean mode
string[]$tags array of tags
Exceptions

Implements Zend_Cache_Backend_Interface.

Definition at line 117 of file Eaccelerator.php.

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  }
_log($message, $priority=4)
Definition: Backend.php:273
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ getCapabilities()

getCapabilities ( )

Return an associative array of capabilities (booleans) of the backend

The array must include these keys :

  • automatic_cleaning (is automating cleaning necessary)
  • tags (are tags supported)
  • expired_read (is it possible to read expired cache records (for doNotTestCacheValidity option for example))
  • priority does the backend deal with priority when saving
  • infinite_lifetime (is infinite lifetime can work with this backend)
  • get_list (is it possible to get the list of cache ids and the complete list of tags)
Returns
array associative of with capabilities

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 305 of file Eaccelerator.php.

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  }

◆ getFillingPercentage()

getFillingPercentage ( )

Return the filling percentage of the backend storage

Exceptions

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 146 of file Eaccelerator.php.

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  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ getIds()

getIds ( )

Return an array of stored cache ids

Returns
string[] array of stored cache ids (string) @SuppressWarnings(PHPMD.UnusedLocalVariable)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 223 of file Eaccelerator.php.

224  {
225  $res = [];
226  $array = eaccelerator_list_keys();
227  foreach ($array as $key => $info) {
228  $res[] = $key;
229  }
230  return $res;
231  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ getIdsMatchingAnyTags()

getIdsMatchingAnyTags (   $tags = [])

Return an array of stored cache ids which match any given tags

In case of multiple tags, a logical AND is made between tags

Parameters
string[]$tags array of tags
Returns
string[] array of any matching cache ids (string) @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 211 of file Eaccelerator.php.

212  {
213  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
214  return [];
215  }
_log($message, $priority=4)
Definition: Backend.php:273

◆ getIdsMatchingTags()

getIdsMatchingTags (   $tags = [])

Return an array of stored cache ids which match given tags

In case of multiple tags, a logical AND is made between tags

Parameters
array$tagsarray of tags
Returns
string[] array of matching cache ids (string) @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 181 of file Eaccelerator.php.

182  {
183  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
184  return [];
185  }
_log($message, $priority=4)
Definition: Backend.php:273

◆ getIdsNotMatchingTags()

getIdsNotMatchingTags (   $tags = [])

Return an array of stored cache ids which don't match given tags

In case of multiple tags, a logical OR is made between tags

Parameters
string[]$tags array of tags
Returns
string[] array of not matching cache ids (string) @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 196 of file Eaccelerator.php.

197  {
198  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
199  return [];
200  }
_log($message, $priority=4)
Definition: Backend.php:273

◆ getMetadatas()

getMetadatas (   $id)

Return an array of metadatas for the given cache id

The array must include these keys :

  • expire : the expire timestamp
  • tags : a string array of tags
  • mtime : timestamp of last modification time
Parameters
string$idcache id
Returns
array|false array of metadatas (false if the cache id is not found) @SuppressWarnings(PHPMD.UnusedLocalVariable)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 245 of file Eaccelerator.php.

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  }
$id
Definition: fieldset.phtml:14

◆ getTags()

getTags ( )

Return an array of stored tags

Returns
string[] array of stored tags (string)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 166 of file Eaccelerator.php.

167  {
168  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
169  return [];
170  }
_log($message, $priority=4)
Definition: Backend.php:273

◆ load()

load (   $id,
  $doNotTestCacheValidity = false 
)

Test if a cache is available for the given id and (if yes) return it (false else)

WARNING $doNotTestCacheValidity=true is unsupported by the Eaccelerator backend

Parameters
string$idcache id
boolean$doNotTestCacheValidityif set to true, the cache validity won't be tested
Returns
string cached datas (or false) @SuppressWarnings(PHPMD.UnusedFormalParameter)

Implements Zend_Cache_Backend_Interface.

Definition at line 44 of file Eaccelerator.php.

45  {
46  $tmp = eaccelerator_get($id);
47  if (is_array($tmp)) {
48  return $tmp[0];
49  }
50  return false;
51  }
$id
Definition: fieldset.phtml:14

◆ remove()

remove (   $id)

Remove a cache record

Parameters
string$idcache id
Returns
bool true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 96 of file Eaccelerator.php.

97  {
98  return eaccelerator_rm($id);
99  }
$id
Definition: fieldset.phtml:14

◆ save()

save (   $data,
  $id,
  $tags = [],
  $specificLifetime = false 
)

Save some string datas into a cache record

Note : $data is always "string" (serialization is done by the core not by the backend)

Parameters
string$datadatas to cache
string$idcache id
string[]$tags array of strings, the cache record will be tagged by each string entry
int | bool$specificLifetimeInteger to set a specific lifetime or null for infinite lifetime
Returns
bool true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 80 of file Eaccelerator.php.

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  }
$id
Definition: fieldset.phtml:14
_log($message, $priority=4)
Definition: Backend.php:273
getLifetime($specificLifetime)
Definition: Backend.php:143

◆ test()

test (   $id)

Test if a cache is available or not (for the given id)

Parameters
string$idcache id
Returns
mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record

Implements Zend_Cache_Backend_Interface.

Definition at line 59 of file Eaccelerator.php.

60  {
61  $tmp = eaccelerator_get($id);
62  if (is_array($tmp)) {
63  return $tmp[1];
64  }
65  return false;
66  }
$id
Definition: fieldset.phtml:14

◆ touch()

touch (   $id,
  $extraLifetime 
)

Give (if possible) an extra lifetime to the given cache id

Parameters
string$idcache id
int$extraLifetime
Returns
bool true if ok

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 269 of file Eaccelerator.php.

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  }
$id
Definition: fieldset.phtml:14

Field Documentation

◆ TAGS_UNSUPPORTED_BY_CLEAN_OF_EACCELERATOR_BACKEND

const TAGS_UNSUPPORTED_BY_CLEAN_OF_EACCELERATOR_BACKEND
Initial value:
=
'Magento\Framework\Cache\Backend\Eaccelerator::clean() : tags are unsupported by the Eaccelerator backend'

Log message

Definition at line 14 of file Eaccelerator.php.

◆ TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND

const TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND
Initial value:
=
'Magento\Framework\Cache\Backend\Eaccelerator::save() : tags are unsupported by the Eaccelerator backend'

Definition at line 17 of file Eaccelerator.php.


The documentation for this class was generated from the following file: