summaryrefslogtreecommitdiff
path: root/vendor/symfony/cache/Adapter/NullAdapter.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/cache/Adapter/NullAdapter.php')
-rw-r--r--vendor/symfony/cache/Adapter/NullAdapter.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/vendor/symfony/cache/Adapter/NullAdapter.php b/vendor/symfony/cache/Adapter/NullAdapter.php
new file mode 100644
index 0000000..d5d2ef6
--- /dev/null
+++ b/vendor/symfony/cache/Adapter/NullAdapter.php
@@ -0,0 +1,105 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Cache\Adapter;
13
14use Psr\Cache\CacheItemInterface;
15use Symfony\Component\Cache\CacheItem;
16use Symfony\Contracts\Cache\CacheInterface;
17
18/**
19 * @author Titouan Galopin <galopintitouan@gmail.com>
20 */
21class NullAdapter implements AdapterInterface, CacheInterface
22{
23 private static \Closure $createCacheItem;
24
25 public function __construct()
26 {
27 self::$createCacheItem ??= \Closure::bind(
28 static function ($key) {
29 $item = new CacheItem();
30 $item->key = $key;
31 $item->isHit = false;
32
33 return $item;
34 },
35 null,
36 CacheItem::class
37 );
38 }
39
40 public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed
41 {
42 $save = true;
43
44 return $callback((self::$createCacheItem)($key), $save);
45 }
46
47 public function getItem(mixed $key): CacheItem
48 {
49 return (self::$createCacheItem)($key);
50 }
51
52 public function getItems(array $keys = []): iterable
53 {
54 return $this->generateItems($keys);
55 }
56
57 public function hasItem(mixed $key): bool
58 {
59 return false;
60 }
61
62 public function clear(string $prefix = ''): bool
63 {
64 return true;
65 }
66
67 public function deleteItem(mixed $key): bool
68 {
69 return true;
70 }
71
72 public function deleteItems(array $keys): bool
73 {
74 return true;
75 }
76
77 public function save(CacheItemInterface $item): bool
78 {
79 return true;
80 }
81
82 public function saveDeferred(CacheItemInterface $item): bool
83 {
84 return true;
85 }
86
87 public function commit(): bool
88 {
89 return true;
90 }
91
92 public function delete(string $key): bool
93 {
94 return $this->deleteItem($key);
95 }
96
97 private function generateItems(array $keys): \Generator
98 {
99 $f = self::$createCacheItem;
100
101 foreach ($keys as $key) {
102 yield $key => $f($key);
103 }
104 }
105}