Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
Zend_Cache_Backend_ZendPlatform Class Reference
Inheritance diagram for Zend_Cache_Backend_ZendPlatform:
Zend_Cache_Backend 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())
 
- 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_PREFIX = "internal_ZPtag:"
 

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 42 of file ZendPlatform.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = array())

Constructor Validate that the Zend Platform is loaded and licensed

Parameters
array$optionsAssociative array of options
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 57 of file ZendPlatform.php.

58  {
59  if (!function_exists('accelerator_license_info')) {
60  Zend_Cache::throwException('The Zend Platform extension must be loaded for using this backend !');
61  }
62  if (!function_exists('accelerator_get_configuration')) {
63  $licenseInfo = accelerator_license_info();
64  Zend_Cache::throwException('The Zend Platform extension is not loaded correctly: '.$licenseInfo['failure_reason']);
65  }
66  $accConf = accelerator_get_configuration();
67  if (@!$accConf['output_cache_licensed']) {
68  Zend_Cache::throwException('The Zend Platform extension does not have the proper license to use content caching features');
69  }
70  if (@!$accConf['output_cache_enabled']) {
71  Zend_Cache::throwException('The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
72  }
73  if (!is_writable($accConf['output_cache_dir'])) {
74  Zend_Cache::throwException('The cache copies directory \''. ini_get('zend_accelerator.output_cache_dir') .'\' must be writable !');
75  }
76  parent:: __construct($options);
77  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
is_writable($path)
Definition: io.php:25

Member Function Documentation

◆ clean()

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

Clean some cache records

Available modes are : Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) This mode is not supported in this backend Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags ($tags can be an array of strings or a single string) Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => unsupported Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags ($tags can be an array of strings or a single string)

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 185 of file ZendPlatform.php.

186  {
187  switch ($mode) {
190  $cache_dir = ini_get('zend_accelerator.output_cache_dir');
191  if (!$cache_dir) {
192  return false;
193  }
194  $cache_dir .= '/.php_cache_api/';
195  return $this->_clean($cache_dir, $mode);
196  break;
198  $idlist = null;
199  foreach ($tags as $tag) {
200  $next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
201  if ($idlist) {
202  $idlist = array_intersect_assoc($idlist, $next_idlist);
203  } else {
204  $idlist = $next_idlist;
205  }
206  if (count($idlist) == 0) {
207  // if ID list is already empty - we may skip checking other IDs
208  $idlist = null;
209  break;
210  }
211  }
212  if ($idlist) {
213  foreach ($idlist as $id) {
214  output_cache_remove_key($id);
215  }
216  }
217  return true;
218  break;
220  $this->_log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend");
221  return false;
222  break;
224  $idlist = null;
225  foreach ($tags as $tag) {
226  $next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
227  if ($idlist) {
228  $idlist = array_merge_recursive($idlist, $next_idlist);
229  } else {
230  $idlist = $next_idlist;
231  }
232  if (count($idlist) == 0) {
233  // if ID list is already empty - we may skip checking other IDs
234  $idlist = null;
235  break;
236  }
237  }
238  if ($idlist) {
239  foreach ($idlist as $id) {
240  output_cache_remove_key($id);
241  }
242  }
243  return true;
244  break;
245  default:
246  Zend_Cache::throwException('Invalid mode for clean() method');
247  break;
248  }
249  }
$id
Definition: fieldset.phtml:14
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

◆ load()

load (   $id,
  $doNotTestCacheValidity = false 
)

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

Parameters
string$idCache id
boolean$doNotTestCacheValidityIf set to true, the cache validity won't be tested
Returns
string Cached data (or false)

Implements Zend_Cache_Backend_Interface.

Definition at line 86 of file ZendPlatform.php.

87  {
88  // doNotTestCacheValidity implemented by giving zero lifetime to the cache
89  if ($doNotTestCacheValidity) {
90  $lifetime = 0;
91  } else {
92  $lifetime = $this->_directives['lifetime'];
93  }
94  $res = output_cache_get($id, $lifetime);
95  if($res) {
96  return $res[0];
97  } else {
98  return false;
99  }
100  }
$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 161 of file ZendPlatform.php.

162  {
163  return output_cache_remove_key($id);
164  }
$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$dataData 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 130 of file ZendPlatform.php.

131  {
132  if (!($specificLifetime === false)) {
133  $this->_log("Zend_Cache_Backend_ZendPlatform::save() : non false specifc lifetime is unsuported for this backend");
134  }
135 
136  $lifetime = $this->_directives['lifetime'];
137  $result1 = output_cache_put($id, array($data, time()));
138  $result2 = (count($tags) == 0);
139 
140  foreach ($tags as $tag) {
141  $tagid = self::TAGS_PREFIX.$tag;
142  $old_tags = output_cache_get($tagid, $lifetime);
143  if ($old_tags === false) {
144  $old_tags = array();
145  }
146  $old_tags[$id] = $id;
147  output_cache_remove_key($tagid);
148  $result2 = output_cache_put($tagid, $old_tags);
149  }
150 
151  return $result1 && $result2;
152  }
$id
Definition: fieldset.phtml:14
_log($message, $priority=4)
Definition: Backend.php:273

◆ test()

test (   $id)

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

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

Implements Zend_Cache_Backend_Interface.

Definition at line 109 of file ZendPlatform.php.

110  {
111  $result = output_cache_get($id, $this->_directives['lifetime']);
112  if ($result) {
113  return $result[1];
114  }
115  return false;
116  }
$id
Definition: fieldset.phtml:14

Field Documentation

◆ TAGS_PREFIX

const TAGS_PREFIX = "internal_ZPtag:"

internal ZP prefix

Definition at line 47 of file ZendPlatform.php.


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