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