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

Public Member Functions

 __construct (array $options=array())
 
 load ($id, $doNotTestCacheValidity=false)
 
 test ($id)
 
 save ($data, $id, $tags=array(), $specificLifetime=false)
 
 remove ($id)
 
 clean ($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
 
 isAutomaticCleaningAvailable ()
 
 getFillingPercentage ()
 
 getTags ()
 
 getIdsMatchingTags ($tags=array())
 
 getIdsNotMatchingTags ($tags=array())
 
 getIdsMatchingAnyTags ($tags=array())
 
 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_APC_BACKEND = 'Zend_Cache_Backend_Apc::clean() : tags are unsupported by the Apc backend'
 
const TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::save() : tags are unsupported by the Apc 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 41 of file Apc.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = array())

Constructor

Parameters
array$optionsassociative array of options
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 56 of file Apc.php.

57  {
58  if (!extension_loaded('apc')) {
59  Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
60  }
61  parent::__construct($options);
62  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

Member Function Documentation

◆ clean()

clean (   $mode = Zend_Cache::CLEANING_MODE_ALL,
  $tags = array() 
)

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
array$tagsarray of tags
Exceptions
Zend_Cache_Exception
Returns
boolean true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 145 of file Apc.php.

146  {
147  switch ($mode) {
149  return apc_clear_cache('user');
150  break;
152  $this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
153  break;
157  $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
158  break;
159  default:
160  Zend_Cache::throwException('Invalid mode for clean() method');
161  break;
162  }
163  }
const CLEANING_MODE_OLD
Definition: Cache.php:73
_log($message, $priority=4)
Definition: Backend.php:273
const CLEANING_MODE_NOT_MATCHING_TAG
Definition: Cache.php:75
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
const CLEANING_MODE_MATCHING_ANY_TAG
Definition: Cache.php:76
const CLEANING_MODE_MATCHING_TAG
Definition: Cache.php:74

◆ 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 343 of file Apc.php.

344  {
345  return array(
346  'automatic_cleaning' => false,
347  'tags' => false,
348  'expired_read' => false,
349  'priority' => false,
350  'infinite_lifetime' => false,
351  'get_list' => true
352  );
353  }

◆ getFillingPercentage()

getFillingPercentage ( )

Return the filling percentage of the backend storage

Exceptions
Zend_Cache_Exception
Returns
int integer between 0 and 100

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 184 of file Apc.php.

185  {
186  $mem = apc_sma_info(true);
187  $memSize = $mem['num_seg'] * $mem['seg_size'];
188  $memAvailable= $mem['avail_mem'];
189  $memUsed = $memSize - $memAvailable;
190  if ($memSize == 0) {
191  Zend_Cache::throwException('can\'t get apc memory size');
192  }
193  if ($memUsed > $memSize) {
194  return 100;
195  }
196  return ((int) (100. * ($memUsed / $memSize)));
197  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ getIds()

getIds ( )

Return an array of stored cache ids

Returns
array array of stored cache ids (string)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 257 of file Apc.php.

258  {
259  $ids = array();
260  $iterator = new APCIterator('user', null, APC_ITER_KEY);
261  foreach ($iterator as $item) {
262  $ids[] = $item['key'];
263  }
264 
265  return $ids;
266  }

◆ getIdsMatchingAnyTags()

getIdsMatchingAnyTags (   $tags = array())

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
array$tagsarray of tags
Returns
array array of any matching cache ids (string)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 246 of file Apc.php.

247  {
248  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
249  return array();
250  }
_log($message, $priority=4)
Definition: Backend.php:273

◆ getIdsMatchingTags()

getIdsMatchingTags (   $tags = array())

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
array array of matching cache ids (string)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 218 of file Apc.php.

219  {
220  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
221  return array();
222  }
_log($message, $priority=4)
Definition: Backend.php:273

◆ getIdsNotMatchingTags()

getIdsNotMatchingTags (   $tags = array())

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
array$tagsarray of tags
Returns
array array of not matching cache ids (string)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 232 of file Apc.php.

233  {
234  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
235  return array();
236  }
_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 array of metadatas (false if the cache id is not found)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 279 of file Apc.php.

280  {
281  $tmp = apc_fetch($id);
282  if (is_array($tmp)) {
283  $data = $tmp[0];
284  $mtime = $tmp[1];
285  if (!isset($tmp[2])) {
286  // because this record is only with 1.7 release
287  // if old cache records are still there...
288  return false;
289  }
290  $lifetime = $tmp[2];
291  return array(
292  'expire' => $mtime + $lifetime,
293  'tags' => array(),
294  'mtime' => $mtime
295  );
296  }
297  return false;
298  }
$id
Definition: fieldset.phtml:14

◆ getTags()

getTags ( )

Return an array of stored tags

Returns
array array of stored tags (string)

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 204 of file Apc.php.

205  {
206  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
207  return array();
208  }
_log($message, $priority=4)
Definition: Backend.php:273

◆ isAutomaticCleaningAvailable()

isAutomaticCleaningAvailable ( )

Return true if the automatic cleaning is available for the backend

DEPRECATED : use getCapabilities() instead

Deprecated:
Returns
boolean

Definition at line 173 of file Apc.php.

174  {
175  return false;
176  }

◆ 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 Apc backend

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

Implements Zend_Cache_Backend_Interface.

Definition at line 73 of file Apc.php.

74  {
75  $tmp = apc_fetch($id);
76  if (is_array($tmp)) {
77  return $tmp[0];
78  }
79  return false;
80  }
$id
Definition: fieldset.phtml:14

◆ remove()

remove (   $id)

Remove a cache record

Parameters
string$idcache id
Returns
boolean true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 125 of file Apc.php.

126  {
127  return apc_delete($id);
128  }
$id
Definition: fieldset.phtml:14

◆ save()

save (   $data,
  $id,
  $tags = array(),
  $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
array$tagsarray of strings, the cache record will be tagged by each string entry
int$specificLifetimeif != false, set a specific lifetime for this cache record (null => infinite lifetime)
Returns
boolean true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 109 of file Apc.php.

110  {
111  $lifetime = $this->getLifetime($specificLifetime);
112  $result = apc_store($id, array($data, time(), $lifetime), $lifetime);
113  if (count($tags) > 0) {
114  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
115  }
116  return $result;
117  }
$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 88 of file Apc.php.

89  {
90  $tmp = apc_fetch($id);
91  if (is_array($tmp)) {
92  return $tmp[1];
93  }
94  return false;
95  }
$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
boolean true if ok

Implements Zend_Cache_Backend_ExtendedInterface.

Definition at line 307 of file Apc.php.

308  {
309  $tmp = apc_fetch($id);
310  if (is_array($tmp)) {
311  $data = $tmp[0];
312  $mtime = $tmp[1];
313  if (!isset($tmp[2])) {
314  // because this record is only with 1.7 release
315  // if old cache records are still there...
316  return false;
317  }
318  $lifetime = $tmp[2];
319  $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
320  if ($newLifetime <=0) {
321  return false;
322  }
323  apc_store($id, array($data, time(), $newLifetime), $newLifetime);
324  return true;
325  }
326  return false;
327  }
$id
Definition: fieldset.phtml:14

Field Documentation

◆ TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND

const TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::clean() : tags are unsupported by the Apc backend'

Log message

Definition at line 46 of file Apc.php.

◆ TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND

const TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::save() : tags are unsupported by the Apc backend'

Definition at line 47 of file Apc.php.


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