1 | <?php |
||
18 | class LoggerCache implements Cache, CacheDecorator |
||
19 | { |
||
20 | use CacheDecoratorTrait, LoggerCacheTrait; |
||
21 | |||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | private $withExceptions; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $logLevel; |
||
31 | |||
32 | /** |
||
33 | * SilentCacheDecorator constructor. |
||
34 | * |
||
35 | * @param Cache $cache |
||
36 | * @param bool $withExceptions |
||
37 | * @param LoggerInterface $logger |
||
38 | * @param string $logLevel |
||
39 | */ |
||
40 | 1 | public function __construct( |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 1 | public function set($key, $value, $timeToLive = null) |
|
56 | { |
||
57 | 1 | return $this->call( |
|
58 | function() use ($key, $value, $timeToLive) { |
||
59 | 1 | return $this->cache->set($key, $value, $timeToLive); |
|
60 | 1 | }, |
|
61 | 1 | __METHOD__, |
|
62 | 1 | [$key, $value, $timeToLive] |
|
63 | ); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 1 | public function has($key) |
|
70 | { |
||
71 | 1 | return $this->call( |
|
72 | function() use ($key) { |
||
73 | 1 | return $this->cache->has($key); |
|
74 | 1 | }, |
|
75 | 1 | __METHOD__, |
|
76 | 1 | [$key] |
|
77 | ); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | 1 | public function get($key, $default = null) |
|
84 | { |
||
85 | 1 | return $this->call( |
|
86 | function() use ($key, $default) { |
||
87 | 1 | return $this->cache->get($key, $default); |
|
88 | 1 | }, |
|
89 | 1 | __METHOD__, |
|
90 | 1 | [$key, $default] |
|
91 | ); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | 1 | public function demand($key) |
|
98 | { |
||
99 | 1 | return $this->call( |
|
100 | function() use ($key) { |
||
101 | 1 | return $this->cache->demand($key); |
|
102 | 1 | }, |
|
103 | 1 | __METHOD__, |
|
104 | 1 | [$key] |
|
105 | ); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | 1 | public function delete($key) |
|
112 | { |
||
113 | 1 | return $this->call( |
|
114 | function() use ($key) { |
||
115 | 1 | return $this->cache->delete($key); |
|
116 | 1 | }, |
|
117 | 1 | __METHOD__, |
|
118 | 1 | [$key] |
|
119 | ); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | 1 | public function flush() |
|
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | 1 | public function setItems(array $items, $timeToLive = null) |
|
139 | { |
||
140 | 1 | return $this->call( |
|
141 | function() use ($items, $timeToLive) { |
||
142 | 1 | return $this->cache->setItems($items, $timeToLive); |
|
143 | 1 | }, |
|
144 | 1 | __METHOD__, |
|
145 | 1 | [$items, $timeToLive] |
|
146 | ); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | 1 | public function getItems(array $keys) |
|
153 | { |
||
154 | 1 | return $this->call( |
|
155 | function() use ($keys) { |
||
156 | 1 | return $this->cache->getItems($keys); |
|
157 | 1 | }, |
|
158 | 1 | __METHOD__, |
|
159 | 1 | [$keys] |
|
160 | ); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | 1 | public function deleteItems(array $keys) |
|
167 | { |
||
168 | 1 | return $this->call( |
|
169 | function() use ($keys) { |
||
170 | 1 | return $this->cache->deleteItems($keys); |
|
171 | 1 | }, |
|
172 | 1 | __METHOD__, |
|
173 | 1 | [$keys] |
|
174 | ); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Gets the remaining time to live for an item |
||
179 | * |
||
180 | * @param $key |
||
181 | * |
||
182 | * @return int|null |
||
183 | */ |
||
184 | 1 | public function getTimeToLive($key) |
|
193 | |||
194 | /** |
||
195 | * @param callable $callable |
||
196 | * |
||
197 | * @param string $method |
||
198 | * @param array $arguments |
||
199 | * |
||
200 | * @return mixed |
||
201 | * @throws BackendOperationFailedException |
||
202 | * @throws CacheException |
||
203 | */ |
||
204 | 1 | protected function call(callable $callable, $method, $arguments = []) |
|
221 | |||
222 | /** |
||
223 | * @param Exception $exception |
||
224 | * @param string $method |
||
225 | * @param array $arguments |
||
226 | * |
||
227 | * @return bool |
||
228 | */ |
||
229 | 1 | protected function logException(Exception $exception, $method, array $arguments) |
|
239 | } |
||
240 |