1 | <?php |
||
16 | class ChainCache extends TaggableCache |
||
17 | { |
||
18 | use MultiCacheTrait; |
||
19 | |||
20 | /** |
||
21 | * Stored items |
||
22 | * |
||
23 | * @var Cache[] |
||
24 | */ |
||
25 | private $caches = []; |
||
26 | |||
27 | /** |
||
28 | * Pushes a cache in the chain |
||
29 | * |
||
30 | * @param Cache $cache |
||
31 | * |
||
32 | * @return $this |
||
33 | */ |
||
34 | 1 | public function pushCache(Cache $cache) |
|
40 | |||
41 | /** |
||
42 | * Returns the caches in the chain |
||
43 | * |
||
44 | * @return \Cmp\Cache\Cache[] |
||
45 | */ |
||
46 | 1 | public function getCaches() |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 1 | public function set($key, $item, $timeToLive = null) |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 1 | public function has($key) |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 1 | public function get($key, $default = null) |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 1 | public function demand($key) |
|
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | 1 | public function delete($key) |
|
|
|||
112 | { |
||
113 | 1 | $success = true; |
|
114 | 1 | foreach ($this->caches as $cache) { |
|
115 | 1 | $success = $success && $cache->delete($key); |
|
116 | 1 | } |
|
117 | |||
118 | 1 | return $success; |
|
119 | } |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | 1 | public function flush() |
|
125 | { |
||
126 | 1 | $success = true; |
|
127 | 1 | foreach ($this->caches as $cache) { |
|
128 | 1 | $success = $success && $cache->flush(); |
|
129 | 1 | } |
|
130 | |||
131 | 1 | return $success; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Gets the remaining time to live for an item |
||
136 | * |
||
137 | * @param $key |
||
138 | * |
||
139 | * @return int|null |
||
140 | */ |
||
141 | 1 | public function getTimeToLive($key) |
|
152 | |||
153 | /** |
||
154 | * @param string $index |
||
155 | * @param string $key |
||
156 | * @param string $item |
||
157 | * @param int|null $timeToLive |
||
158 | */ |
||
159 | 1 | private function populatePreviousCaches($index, $key, $item, $timeToLive) |
|
165 | } |
||
166 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.