1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MovingImage\Bundle\VMProApiBundle\Decorator; |
6
|
|
|
|
7
|
|
|
use Psr\Cache\CacheItemInterface; |
8
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Decorator that wraps around any CacheItemPoolInterface implementation |
12
|
|
|
* and overrides the `isHit` method by always returning false. |
13
|
|
|
* Therefore, this is a CacheItemPool implementation useful for forcing cache to be refreshed. |
14
|
|
|
*/ |
15
|
|
|
class BlackholeCacheItemPoolDecorator implements CacheItemPoolInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Decorated CacheItemPool implementation. |
19
|
|
|
* |
20
|
|
|
* @var CacheItemPoolInterface |
21
|
|
|
*/ |
22
|
|
|
private $cacheItemPool; |
23
|
|
|
|
24
|
|
|
public function __construct(CacheItemPoolInterface $cacheItemPool) |
25
|
16 |
|
{ |
26
|
|
|
$this->cacheItemPool = $cacheItemPool; |
27
|
16 |
|
} |
28
|
16 |
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function getItem($key): CacheItemInterface |
33
|
14 |
|
{ |
34
|
|
|
return new BlackholeCacheItemDecorator($this->cacheItemPool->getItem($key)); |
35
|
14 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function getItems(array $keys = []) |
41
|
2 |
|
{ |
42
|
|
|
$items = []; |
43
|
2 |
|
foreach ($this->cacheItemPool->getItems($keys) as $item) { |
44
|
2 |
|
$items[] = new BlackholeCacheItemDecorator($item); |
45
|
2 |
|
} |
46
|
2 |
|
|
47
|
|
|
return $items; |
48
|
2 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function hasItem($key): bool |
54
|
|
|
{ |
55
|
|
|
return $this->cacheItemPool->hasItem($key); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function clear(): bool |
62
|
|
|
{ |
63
|
|
|
return $this->cacheItemPool->clear(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function deleteItem($key): bool |
70
|
|
|
{ |
71
|
|
|
return $this->cacheItemPool->deleteItem($key); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function deleteItems(array $keys): bool |
78
|
|
|
{ |
79
|
|
|
return $this->cacheItemPool->deleteItems($keys); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function save(CacheItemInterface $item): bool |
86
|
8 |
|
{ |
87
|
|
|
if ($item instanceof BlackholeCacheItemDecorator) { |
88
|
8 |
|
$item = $item->getDecoratedItem(); |
89
|
8 |
|
} |
90
|
8 |
|
|
91
|
|
|
return $this->cacheItemPool->save($item); |
92
|
8 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function saveDeferred(CacheItemInterface $item): bool |
98
|
|
|
{ |
99
|
|
|
if ($item instanceof BlackholeCacheItemDecorator) { |
100
|
|
|
$item = $item->getDecoratedItem(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->cacheItemPool->saveDeferred($item); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function commit(): bool |
110
|
|
|
{ |
111
|
|
|
return $this->cacheItemPool->commit(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|