1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* System cache model
* support id and tags prefix support,
*/
namespace Magento\Framework\App;
class Cache implements CacheInterface
{
/**
* @var string
*/
protected $_frontendIdentifier = \Magento\Framework\App\Cache\Frontend\Pool::DEFAULT_FRONTEND_ID;
/**
* @var \Magento\Framework\App\Cache\Frontend\Pool
*/
protected $_frontendPool;
/**
* Cache frontend API
*
* @var \Magento\Framework\Cache\FrontendInterface
*/
protected $_frontend;
/**
* @param \Magento\Framework\App\Cache\Frontend\Pool $frontendPool
*/
public function __construct(\Magento\Framework\App\Cache\Frontend\Pool $frontendPool)
{
$this->_frontendPool = $frontendPool;
$this->_frontend = $frontendPool->get($this->_frontendIdentifier);
}
/**
* Get cache frontend API object
*
* @return \Magento\Framework\Cache\FrontendInterface
*/
public function getFrontend()
{
return $this->_frontend;
}
/**
* Load data from cache by id
*
* @param string $identifier
* @return string
*/
public function load($identifier)
{
return $this->_frontend->load($identifier);
}
/**
* Save data
*
* @param string $data
* @param string $identifier
* @param array $tags
* @param int $lifeTime
* @return bool
*/
public function save($data, $identifier, $tags = [], $lifeTime = null)
{
return $this->_frontend->save((string)$data, $identifier, $tags, $lifeTime);
}
/**
* Remove cached data by identifier
*
* @param string $identifier
* @return bool
*/
public function remove($identifier)
{
return $this->_frontend->remove($identifier);
}
/**
* Clean cached data by specific tag
*
* @param array $tags
* @return bool
*/
public function clean($tags = [])
{
if ($tags) {
$result = $this->_frontend->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, (array)$tags);
} else {
/** @deprecated special case of cleaning by empty tags is deprecated after 2.0.0.0-dev42 */
$result = false;
/** @var $cacheFrontend \Magento\Framework\Cache\FrontendInterface */
foreach ($this->_frontendPool as $cacheFrontend) {
if ($cacheFrontend->clean()) {
$result = true;
}
}
}
return $result;
}
}