Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Core.php
Go to the documentation of this file.
1 <?php
7 
8 class Core extends \Zend_Cache_Core
9 {
19  protected $_specificOptions = ['backend_decorators' => [], 'disable_save' => false];
20 
29  protected function _id($cacheId)
30  {
31  if ($cacheId !== null) {
32  $cacheId = str_replace('.', '__', $cacheId); //reduce collision chances
33  $cacheId = preg_replace('/([^a-zA-Z0-9_]{1,1})/', '_', $cacheId);
34  if (isset($this->_options['cache_id_prefix'])) {
35  $cacheId = $this->_options['cache_id_prefix'] . $cacheId;
36  }
37  }
38  return $cacheId;
39  }
40 
47  protected function _tags($tags)
48  {
49  foreach ($tags as $key => $tag) {
50  $tags[$key] = $this->_id($tag);
51  }
52  return $tags;
53  }
54 
68  public function save($data, $cacheId = null, $tags = [], $specificLifetime = false, $priority = 8)
69  {
70  if ($this->getOption('disable_save')) {
71  return true;
72  }
73  $tags = $this->_tags($tags);
74  return parent::save($data, $cacheId, $tags, $specificLifetime, $priority);
75  }
76 
95  public function clean($mode = 'all', $tags = [])
96  {
97  $tags = $this->_tags($tags);
98  return parent::clean($mode, $tags);
99  }
100 
109  public function getIdsMatchingTags($tags = [])
110  {
111  $tags = $this->_tags($tags);
112  return parent::getIdsMatchingTags($tags);
113  }
114 
123  public function getIdsNotMatchingTags($tags = [])
124  {
125  $tags = $this->_tags($tags);
126  return parent::getIdsNotMatchingTags($tags);
127  }
128 
135  public function setBackend(\Zend_Cache_Backend $backendObject)
136  {
137  $backendObject = $this->_decorateBackend($backendObject);
138  parent::setBackend($backendObject);
139  }
140 
147  protected function _decorateBackend(\Zend_Cache_Backend $backendObject)
148  {
149  if (!is_array($this->_specificOptions['backend_decorators'])) {
150  \Zend_Cache::throwException("'backend_decorator' option should be an array");
151  }
152 
153  foreach ($this->_specificOptions['backend_decorators'] as $decoratorName => $decoratorOptions) {
154  if (!is_array($decoratorOptions) || !array_key_exists('class', $decoratorOptions)) {
156  "Concrete decorator options in '" . $decoratorName . "' should be an array containing 'class' key"
157  );
158  }
159  $classOptions = array_key_exists('options', $decoratorOptions) ? $decoratorOptions['options'] : [];
160  $classOptions['concrete_backend'] = $backendObject;
161 
162  if (!class_exists($decoratorOptions['class'])) {
164  "Class '" . $decoratorOptions['class'] . "' specified in '" . $decoratorName . "' does not exist"
165  );
166  }
167 
168  $backendObject = new $decoratorOptions['class']($classOptions);
169  if (!$backendObject instanceof \Magento\Framework\Cache\Backend\Decorator\AbstractDecorator) {
171  "Decorator in '" .
172  $decoratorName .
173  "' should extend \Magento\Framework\Cache\Backend\Decorator\AbstractDecorator"
174  );
175  }
176  }
177 
178  return $backendObject;
179  }
180 }
save($data, $cacheId=null, $tags=[], $specificLifetime=false, $priority=8)
Definition: Core.php:68
setBackend(\Zend_Cache_Backend $backendObject)
Definition: Core.php:135
_decorateBackend(\Zend_Cache_Backend $backendObject)
Definition: Core.php:147
getOption($name)
Definition: Core.php:236
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
clean($mode='all', $tags=[])
Definition: Core.php:95
getIdsNotMatchingTags($tags=[])
Definition: Core.php:123
getIdsMatchingTags($tags=[])
Definition: Core.php:109