|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Cache\Adapter;
|
13 | 13 |
|
14 |
| -use Psr\Cache\CacheItemInterface; |
15 | 14 | use Psr\Log\LoggerAwareInterface;
|
16 | 15 | use Psr\Log\LoggerInterface;
|
17 | 16 | use Psr\Log\NullLogger;
|
18 | 17 | use Symfony\Component\Cache\CacheItem;
|
19 | 18 | use Symfony\Component\Cache\Exception\InvalidArgumentException;
|
20 | 19 | use Symfony\Component\Cache\ResettableInterface;
|
21 |
| -use Symfony\Component\Cache\Traits\AbstractTrait; |
| 20 | +use Symfony\Component\Cache\Traits\AbstractAdapterTrait; |
22 | 21 | use Symfony\Component\Cache\Traits\ContractsTrait;
|
23 | 22 | use Symfony\Contracts\Cache\CacheInterface;
|
24 | 23 |
|
|
27 | 26 | */
|
28 | 27 | abstract class AbstractAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface
|
29 | 28 | {
|
30 |
| - use AbstractTrait; |
| 29 | + use AbstractAdapterTrait; |
31 | 30 | use ContractsTrait;
|
32 | 31 |
|
33 | 32 | private static $apcuSupported;
|
34 | 33 | private static $phpFilesSupported;
|
35 | 34 |
|
36 |
| - private $createCacheItem; |
37 |
| - private $mergeByLifetime; |
38 |
| - |
39 | 35 | protected function __construct(string $namespace = '', int $defaultLifetime = 0)
|
40 | 36 | {
|
41 | 37 | $this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace).':';
|
@@ -142,81 +138,6 @@ public static function createConnection($dsn, array $options = [])
|
142 | 138 | throw new InvalidArgumentException(sprintf('Unsupported DSN: %s.', $dsn));
|
143 | 139 | }
|
144 | 140 |
|
145 |
| - /** |
146 |
| - * {@inheritdoc} |
147 |
| - */ |
148 |
| - public function getItem($key) |
149 |
| - { |
150 |
| - if ($this->deferred) { |
151 |
| - $this->commit(); |
152 |
| - } |
153 |
| - $id = $this->getId($key); |
154 |
| - |
155 |
| - $f = $this->createCacheItem; |
156 |
| - $isHit = false; |
157 |
| - $value = null; |
158 |
| - |
159 |
| - try { |
160 |
| - foreach ($this->doFetch([$id]) as $value) { |
161 |
| - $isHit = true; |
162 |
| - } |
163 |
| - } catch (\Exception $e) { |
164 |
| - CacheItem::log($this->logger, 'Failed to fetch key "{key}"', ['key' => $key, 'exception' => $e]); |
165 |
| - } |
166 |
| - |
167 |
| - return $f($key, $value, $isHit); |
168 |
| - } |
169 |
| - |
170 |
| - /** |
171 |
| - * {@inheritdoc} |
172 |
| - */ |
173 |
| - public function getItems(array $keys = []) |
174 |
| - { |
175 |
| - if ($this->deferred) { |
176 |
| - $this->commit(); |
177 |
| - } |
178 |
| - $ids = []; |
179 |
| - |
180 |
| - foreach ($keys as $key) { |
181 |
| - $ids[] = $this->getId($key); |
182 |
| - } |
183 |
| - try { |
184 |
| - $items = $this->doFetch($ids); |
185 |
| - } catch (\Exception $e) { |
186 |
| - CacheItem::log($this->logger, 'Failed to fetch requested items', ['keys' => $keys, 'exception' => $e]); |
187 |
| - $items = []; |
188 |
| - } |
189 |
| - $ids = array_combine($ids, $keys); |
190 |
| - |
191 |
| - return $this->generateItems($items, $ids); |
192 |
| - } |
193 |
| - |
194 |
| - /** |
195 |
| - * {@inheritdoc} |
196 |
| - */ |
197 |
| - public function save(CacheItemInterface $item) |
198 |
| - { |
199 |
| - if (!$item instanceof CacheItem) { |
200 |
| - return false; |
201 |
| - } |
202 |
| - $this->deferred[$item->getKey()] = $item; |
203 |
| - |
204 |
| - return $this->commit(); |
205 |
| - } |
206 |
| - |
207 |
| - /** |
208 |
| - * {@inheritdoc} |
209 |
| - */ |
210 |
| - public function saveDeferred(CacheItemInterface $item) |
211 |
| - { |
212 |
| - if (!$item instanceof CacheItem) { |
213 |
| - return false; |
214 |
| - } |
215 |
| - $this->deferred[$item->getKey()] = $item; |
216 |
| - |
217 |
| - return true; |
218 |
| - } |
219 |
| - |
220 | 141 | /**
|
221 | 142 | * {@inheritdoc}
|
222 | 143 | */
|
@@ -271,33 +192,4 @@ public function commit()
|
271 | 192 |
|
272 | 193 | return $ok;
|
273 | 194 | }
|
274 |
| - |
275 |
| - public function __destruct() |
276 |
| - { |
277 |
| - if ($this->deferred) { |
278 |
| - $this->commit(); |
279 |
| - } |
280 |
| - } |
281 |
| - |
282 |
| - private function generateItems($items, &$keys) |
283 |
| - { |
284 |
| - $f = $this->createCacheItem; |
285 |
| - |
286 |
| - try { |
287 |
| - foreach ($items as $id => $value) { |
288 |
| - if (!isset($keys[$id])) { |
289 |
| - $id = key($keys); |
290 |
| - } |
291 |
| - $key = $keys[$id]; |
292 |
| - unset($keys[$id]); |
293 |
| - yield $key => $f($key, $value, true); |
294 |
| - } |
295 |
| - } catch (\Exception $e) { |
296 |
| - CacheItem::log($this->logger, 'Failed to fetch requested items', ['keys' => array_values($keys), 'exception' => $e]); |
297 |
| - } |
298 |
| - |
299 |
| - foreach ($keys as $key) { |
300 |
| - yield $key => $f($key, null, false); |
301 |
| - } |
302 |
| - } |
303 | 195 | }
|
0 commit comments