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

Public Member Functions

 __construct (array $options=array())
 
 call ($callback, array $parameters=array(), $tags=array(), $specificLifetime=false, $priority=8)
 
 makeId ($callback, 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
 
- 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 36 of file Function.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = array())

Constructor

Parameters
array$optionsAssociative array of options
Returns
void

Definition at line 64 of file Function.php.

65  {
66  foreach ($options as $name => $value) {
67  $this->setOption($name, $value);
68  }
69  $this->setOption('automatic_serialization', true);
70  }
setOption($name, $value)
Definition: Core.php:211
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

Member Function Documentation

◆ call()

call (   $callback,
array  $parameters = array(),
  $tags = array(),
  $specificLifetime = false,
  $priority = 8 
)

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

Parameters
callback$callbackA valid callback
array$parametersFunction parameters
array$tagsCache tags
int$specificLifetimeIf != false, set a specific lifetime for this cache record (null => infinite lifetime)
int$priorityinteger between 0 (very low priority) and 10 (maximum priority) used by some particular backends
Returns
mixed Result

Definition at line 82 of file Function.php.

83  {
84  if (!is_callable($callback, true, $name)) {
85  Zend_Cache::throwException('Invalid callback');
86  }
87 
88  $cacheBool1 = $this->_specificOptions['cache_by_default'];
89  $cacheBool2 = in_array($name, $this->_specificOptions['cached_functions']);
90  $cacheBool3 = in_array($name, $this->_specificOptions['non_cached_functions']);
91  $cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
92  if (!$cache) {
93  // Caching of this callback is disabled
94  return call_user_func_array($callback, $parameters);
95  }
96 
97  $id = $this->_makeId($callback, $parameters);
98  if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1])) {
99  // A cache is available
100  $output = $rs[0];
101  $return = $rs[1];
102  } else {
103  // A cache is not available (or not valid for this frontend)
104  ob_start();
105  ob_implicit_flush(false);
106  $return = call_user_func_array($callback, $parameters);
107  $output = ob_get_clean();
108  $data = array($output, $return);
109  $this->save($data, $id, $tags, $specificLifetime, $priority);
110  }
111 
112  echo $output;
113  return $return;
114  }
$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
load($id, $doNotTestCacheValidity=false, $doNotUnserialize=false)
Definition: Core.php:296
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ makeId()

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

Make a cache id from the function name and parameters

Parameters
callback$callbackA valid callback
array$argsFunction parameters
Exceptions
Zend_Cache_Exception
Returns
string Cache id

Definition at line 134 of file Function.php.

135  {
136  if (!is_callable($callback, true, $name)) {
137  Zend_Cache::throwException('Invalid callback');
138  }
139 
140  // functions, methods and classnames are case-insensitive
141  $name = strtolower($name);
142 
143  // generate a unique id for object callbacks
144  if (is_object($callback)) { // Closures & __invoke
145  $object = $callback;
146  } elseif (isset($callback[0])) { // array($object, 'method')
147  $object = $callback[0];
148  }
149  if (isset($object)) {
150  try {
151  $tmp = @serialize($callback);
152  } catch (Exception $e) {
153  Zend_Cache::throwException($e->getMessage());
154  }
155  if (!$tmp) {
156  $lastErr = error_get_last();
157  Zend_Cache::throwException("Can't serialize callback object to generate id: {$lastErr['message']}");
158  }
159  $name.= '__' . $tmp;
160  }
161 
162  // generate a unique id for arguments
163  $argsStr = '';
164  if ($args) {
165  try {
166  $argsStr = @serialize(array_values($args));
167  } catch (Exception $e) {
168  Zend_Cache::throwException($e->getMessage());
169  }
170  if (!$argsStr) {
171  $lastErr = error_get_last();
172  throw Zend_Cache::throwException("Can't serialize arguments to generate id: {$lastErr['message']}");
173  }
174  }
175 
176  return md5($name . $argsStr);
177  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_specificOptions

$_specificOptions
protected
Initial value:
= array(
'cache_by_default' => true,
'cached_functions' => array(),
'non_cached_functions' => array()
)

Definition at line 52 of file Function.php.


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