Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Manager.php
Go to the documentation of this file.
1 <?php
23 #require_once 'Zend/Cache/Exception.php';
24 
26 #require_once 'Zend/Cache.php';
27 
35 {
39  const PAGECACHE = 'page';
40 
44  const PAGETAGCACHE = 'pagetag';
45 
51  protected $_caches = array();
52 
59  protected $_optionTemplates = array(
60  // Simple Common Default
61  'default' => array(
62  'frontend' => array(
63  'name' => 'Core',
64  'options' => array(
65  'automatic_serialization' => true,
66  ),
67  ),
68  'backend' => array(
69  'name' => 'File',
70  'options' => array(
71  // use system temp dir by default of file backend
72  // 'cache_dir' => '../cache',
73  ),
74  ),
75  ),
76 
77  // Static Page HTML Cache
78  'page' => array(
79  'frontend' => array(
80  'name' => 'Capture',
81  'options' => array(
82  'ignore_user_abort' => true,
83  ),
84  ),
85  'backend' => array(
86  'name' => 'Static',
87  'options' => array(
88  'public_dir' => '../public',
89  ),
90  ),
91  ),
92 
93  // Tag Cache
94  'pagetag' => array(
95  'frontend' => array(
96  'name' => 'Core',
97  'options' => array(
98  'automatic_serialization' => true,
99  'lifetime' => null
100  ),
101  ),
102  'backend' => array(
103  'name' => 'File',
104  'options' => array(
105  // use system temp dir by default of file backend
106  // 'cache_dir' => '../cache',
107  // use default umask of file backend
108  // 'cache_file_umask' => 0644
109  ),
110  ),
111  ),
112  );
113 
122  {
123  $this->_caches[$name] = $cache;
124  return $this;
125  }
126 
134  public function hasCache($name)
135  {
136  if (isset($this->_caches[$name])
137  || $this->hasCacheTemplate($name)
138  ) {
139  return true;
140  }
141  return false;
142  }
143 
151  public function getCache($name)
152  {
153  if (isset($this->_caches[$name])) {
154  return $this->_caches[$name];
155  }
156  if (isset($this->_optionTemplates[$name])) {
157  if ($name == self::PAGECACHE
158  && (!isset($this->_optionTemplates[$name]['backend']['options']['tag_cache'])
159  || !$this->_optionTemplates[$name]['backend']['options']['tag_cache'] instanceof Zend_Cache_Core)
160  ) {
161  $this->_optionTemplates[$name]['backend']['options']['tag_cache']
162  = $this->getCache(self::PAGETAGCACHE);
163  }
164 
165  $this->_caches[$name] = Zend_Cache::factory(
166  $this->_optionTemplates[$name]['frontend']['name'],
167  $this->_optionTemplates[$name]['backend']['name'],
168  isset($this->_optionTemplates[$name]['frontend']['options']) ? $this->_optionTemplates[$name]['frontend']['options'] : array(),
169  isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array(),
170  isset($this->_optionTemplates[$name]['frontend']['customFrontendNaming']) ? $this->_optionTemplates[$name]['frontend']['customFrontendNaming'] : false,
171  isset($this->_optionTemplates[$name]['backend']['customBackendNaming']) ? $this->_optionTemplates[$name]['backend']['customBackendNaming'] : false,
172  isset($this->_optionTemplates[$name]['frontendBackendAutoload']) ? $this->_optionTemplates[$name]['frontendBackendAutoload'] : false
173  );
174 
175  return $this->_caches[$name];
176  }
177  }
178 
184  public function getCaches()
185  {
186  $caches = $this->_caches;
187  foreach ($this->_optionTemplates as $name => $tmp) {
188  if (!isset($caches[$name])) {
189  $caches[$name] = $this->getCache($name);
190  }
191  }
192  return $caches;
193  }
194 
204  public function setCacheTemplate($name, $options)
205  {
206  if ($options instanceof Zend_Config) {
207  $options = $options->toArray();
208  } elseif (!is_array($options)) {
209  #require_once 'Zend/Cache/Exception.php';
210  throw new Zend_Cache_Exception('Options passed must be in'
211  . ' an associative array or instance of Zend_Config');
212  }
213  $this->_optionTemplates[$name] = $options;
214  return $this;
215  }
216 
223  public function hasCacheTemplate($name)
224  {
225  if (isset($this->_optionTemplates[$name])) {
226  return true;
227  }
228  return false;
229  }
230 
237  public function getCacheTemplate($name)
238  {
239  if (isset($this->_optionTemplates[$name])) {
240  return $this->_optionTemplates[$name];
241  }
242  }
243 
255  {
256  if ($options instanceof Zend_Config) {
257  $options = $options->toArray();
258  } elseif (!is_array($options)) {
259  #require_once 'Zend/Cache/Exception.php';
260  throw new Zend_Cache_Exception('Options passed must be in'
261  . ' an associative array or instance of Zend_Config');
262  }
263  if (!isset($this->_optionTemplates[$name])) {
264  throw new Zend_Cache_Exception('A cache configuration template'
265  . 'does not exist with the name "' . $name . '"');
266  }
267  $this->_optionTemplates[$name]
268  = $this->_mergeOptions($this->_optionTemplates[$name], $options);
269  return $this;
270  }
271 
279  protected function _mergeOptions(array $current, array $options)
280  {
281  if (isset($options['frontend']['name'])) {
282  $current['frontend']['name'] = $options['frontend']['name'];
283  }
284  if (isset($options['backend']['name'])) {
285  $current['backend']['name'] = $options['backend']['name'];
286  }
287  if (isset($options['frontend']['options'])) {
288  foreach ($options['frontend']['options'] as $key => $value) {
289  $current['frontend']['options'][$key] = $value;
290  }
291  }
292  if (isset($options['backend']['options'])) {
293  foreach ($options['backend']['options'] as $key => $value) {
294  $current['backend']['options'][$key] = $value;
295  }
296  }
297  if (isset($options['frontend']['customFrontendNaming'])) {
298  $current['frontend']['customFrontendNaming'] = $options['frontend']['customFrontendNaming'];
299  }
300  if (isset($options['backend']['customBackendNaming'])) {
301  $current['backend']['customBackendNaming'] = $options['backend']['customBackendNaming'];
302  }
303  if (isset($options['frontendBackendAutoload'])) {
304  $current['frontendBackendAutoload'] = $options['frontendBackendAutoload'];
305  }
306  return $current;
307  }
308 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
const PAGETAGCACHE
Definition: Manager.php:44
getCacheTemplate($name)
Definition: Manager.php:237
$value
Definition: gender.phtml:16
setCacheTemplate($name, $options)
Definition: Manager.php:204
hasCacheTemplate($name)
Definition: Manager.php:223
setTemplateOptions($name, $options)
Definition: Manager.php:254
static factory($frontend, $backend, $frontendOptions=array(), $backendOptions=array(), $customFrontendNaming=false, $customBackendNaming=false, $autoload=false)
Definition: Cache.php:91
setCache($name, Zend_Cache_Core $cache)
Definition: Manager.php:121
_mergeOptions(array $current, array $options)
Definition: Manager.php:279
if(!isset($_GET['name'])) $name
Definition: log.php:14