Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Cache_Frontend_Class Class Reference
Inheritance diagram for Zend_Cache_Frontend_Class:
Zend_Cache_Core

Public Member Functions

 __construct (array $options=array())
 
 setSpecificLifetime ($specificLifetime=false)
 
 setPriority ($priority)
 
 setOption ($name, $value)
 
 setCachedEntity ($cachedEntity)
 
 setTagsArray ($tags=array())
 
 __call ($name, $parameters)
 
 makeId ($name, array $args=array())
 
- Public Member Functions inherited from Zend_Cache_Core
 __construct ($options=array())
 
 setConfig (Zend_Config $config)
 
 setBackend (Zend_Cache_Backend $backendObject)
 
 getBackend ()
 
 setOption ($name, $value)
 
 getOption ($name)
 
 setLifetime ($newLifetime)
 
 load ($id, $doNotTestCacheValidity=false, $doNotUnserialize=false)
 
 test ($id)
 
 save ($data, $id=null, $tags=array(), $specificLifetime=false, $priority=8)
 
 remove ($id)
 
 clean ($mode='all', $tags=array())
 
 getIdsMatchingTags ($tags=array())
 
 getIdsNotMatchingTags ($tags=array())
 
 getIdsMatchingAnyTags ($tags=array())
 
 getIds ()
 
 getTags ()
 
 getFillingPercentage ()
 
 getMetadatas ($id)
 
 touch ($id, $extraLifetime)
 

Protected Attributes

 $_specificOptions
 
 $_tags = array()
 
 $_specificLifetime = false
 
 $_cachedEntity = null
 
 $_cachedEntityLabel = ''
 
 $_priority = 8
 
- Protected Attributes inherited from Zend_Cache_Core
 $_backend = null
 
 $_options
 
 $_specificOptions = array()
 
 $_extendedBackend = false
 
 $_backendCapabilities = array()
 

Additional Inherited Members

- Data Fields inherited from Zend_Cache_Core
const BACKEND_NOT_SUPPORTS_TAG = 'tags are not supported by the current backend'
 
const BACKEND_NOT_IMPLEMENTS_EXTENDED_IF = 'Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'
 
- Protected Member Functions inherited from Zend_Cache_Core
 _validateIdOrTag ($string)
 
 _validateTagsArray ($tags)
 
 _loggerSanity ()
 
 _log ($message, $priority=4)
 
 _id ($id)
 
- Static Protected Attributes inherited from Zend_Cache_Core
static $_directivesList = array('lifetime', 'logging', 'logger')
 

Detailed Description

Definition at line 35 of file Class.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = array())

Constructor

Parameters
array$optionsAssociative array of options
Exceptions
Zend_Cache_Exception

Definition at line 107 of file Class.php.

108  {
109  foreach ($options as $name => $value) {
110  $this->setOption($name, $value);
111  }
112  if ($this->_specificOptions['cached_entity'] === null) {
113  Zend_Cache::throwException('cached_entity must be set !');
114  }
115  $this->setCachedEntity($this->_specificOptions['cached_entity']);
116  $this->setOption('automatic_serialization', true);
117  }
setCachedEntity($cachedEntity)
Definition: Class.php:167
$value
Definition: gender.phtml:16
setOption($name, $value)
Definition: Class.php:150
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
if(!isset($_GET['name'])) $name
Definition: log.php:14

Member Function Documentation

◆ __call()

__call (   $name,
  $parameters 
)

Main method : call the specified method or get the result from cache

Parameters
string$nameMethod name
array$parametersMethod parameters
Returns
mixed Result
Exceptions
Exception

Definition at line 205 of file Class.php.

206  {
207  $callback = array($this->_cachedEntity, $name);
208 
209  if (!is_callable($callback, false)) {
210  Zend_Cache::throwException('Invalid callback');
211  }
212 
213  $cacheBool1 = $this->_specificOptions['cache_by_default'];
214  $cacheBool2 = in_array($name, $this->_specificOptions['cached_methods']);
215  $cacheBool3 = in_array($name, $this->_specificOptions['non_cached_methods']);
216  $cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
217 
218  if (!$cache) {
219  // We do not have not cache
220  return call_user_func_array($callback, $parameters);
221  }
222 
223  $id = $this->makeId($name, $parameters);
224  if (($rs = $this->load($id)) && (array_key_exists(0, $rs))
225  && (array_key_exists(1, $rs))
226  ) {
227  // A cache is available
228  $output = $rs[0];
229  $return = $rs[1];
230  } else {
231  // A cache is not available (or not valid for this frontend)
232  ob_start();
233  ob_implicit_flush(false);
234 
235  try {
236  $return = call_user_func_array($callback, $parameters);
237  $output = ob_get_clean();
238  $data = array($output, $return);
239 
240  $this->save(
241  $data, $id, $this->_tags, $this->_specificLifetime,
242  $this->_priority
243  );
244  } catch (Exception $e) {
245  ob_end_clean();
246  throw $e;
247  }
248  }
249 
250  echo $output;
251  return $return;
252  }
$id
Definition: fieldset.phtml:14
save($data, $id=null, $tags=array(), $specificLifetime=false, $priority=8)
Definition: Core.php:348
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
makeId($name, array $args=array())
Definition: Class.php:271
load($id, $doNotTestCacheValidity=false, $doNotUnserialize=false)
Definition: Core.php:296
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ makeId()

makeId (   $name,
array  $args = array() 
)

Make a cache id from the method name and parameters

Parameters
string$nameMethod name
array$argsMethod parameters
Returns
string Cache id

Definition at line 271 of file Class.php.

272  {
273  return md5($this->_cachedEntityLabel . '__' . $name . '__' . serialize($args));
274  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setCachedEntity()

setCachedEntity (   $cachedEntity)

Specific method to set the cachedEntity

if set to a class name, we will cache an abstract class and will use only static calls if set to an object, we will cache this object methods

Parameters
mixed$cachedEntity

Definition at line 167 of file Class.php.

168  {
169  if (!is_string($cachedEntity) && !is_object($cachedEntity)) {
171  'cached_entity must be an object or a class name'
172  );
173  }
174 
175  $this->_cachedEntity = $cachedEntity;
176  $this->_specificOptions['cached_entity'] = $cachedEntity;
177 
178  if (is_string($this->_cachedEntity)) {
179  $this->_cachedEntityLabel = $this->_cachedEntity;
180  } else {
181  $ro = new ReflectionObject($this->_cachedEntity);
182  $this->_cachedEntityLabel = $ro->getName();
183  }
184  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ setOption()

setOption (   $name,
  $value 
)

Public frontend to set an option

Just a wrapper to get a specific behaviour for cached_entity

Parameters
string$nameName of the option
mixed$valueValue of the option
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 150 of file Class.php.

151  {
152  if ($name == 'cached_entity') {
153  $this->setCachedEntity($value);
154  } else {
155  parent::setOption($name, $value);
156  }
157  }
setCachedEntity($cachedEntity)
Definition: Class.php:167
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setPriority()

setPriority (   $priority)

Set the priority (used by some particular backends)

Parameters
int$priorityinteger between 0 (very low priority) and 10 (maximum priority)

Definition at line 135 of file Class.php.

136  {
137  $this->_priority = $priority;
138  }

◆ setSpecificLifetime()

setSpecificLifetime (   $specificLifetime = false)

Set a specific life time

Parameters
bool | int$specificLifetime
Returns
void

Definition at line 125 of file Class.php.

126  {
127  $this->_specificLifetime = $specificLifetime;
128  }

◆ setTagsArray()

setTagsArray (   $tags = array())

Set the cache array

Parameters
array$tags
Returns
void

Definition at line 192 of file Class.php.

193  {
194  $this->_tags = $tags;
195  }

Field Documentation

◆ $_cachedEntity

$_cachedEntity = null
protected

Definition at line 83 of file Class.php.

◆ $_cachedEntityLabel

$_cachedEntityLabel = ''
protected

Definition at line 92 of file Class.php.

◆ $_priority

$_priority = 8
protected

Definition at line 99 of file Class.php.

◆ $_specificLifetime

$_specificLifetime = false
protected

Definition at line 76 of file Class.php.

◆ $_specificOptions

$_specificOptions
protected
Initial value:
= array(
'cached_entity' => null,
'cache_by_default' => true,
'cached_methods' => array(),
'non_cached_methods' => array()
)

Definition at line 55 of file Class.php.

◆ $_tags

$_tags = array()
protected

Definition at line 67 of file Class.php.


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