|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the ContentHandler implementation. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace eZ\Publish\Core\Persistence\Cache\Adapter; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; |
|
14
|
|
|
use eZ\Publish\Core\Persistence\Cache\InMemory\InMemoryCache; |
|
15
|
|
|
use Psr\Cache\CacheItemInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Proxy adapter to make sure to clear in-memory cache when needed. |
|
19
|
|
|
* |
|
20
|
|
|
* @intenral Only for type hinting inside eZ\Publish\Core\Persistence\Cache namespace, for external type hint on TagAwareAdapterInterface. |
|
21
|
|
|
*/ |
|
22
|
|
|
class InMemoryClearingProxyAdapter implements TagAwareAdapterInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var TagAwareAdapterInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $pool; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var InMemoryCache |
|
31
|
|
|
*/ |
|
32
|
|
|
private $inMemory; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct(TagAwareAdapterInterface $pool, InMemoryCache $inMemory) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->pool = $pool; |
|
37
|
|
|
$this->inMemory = $inMemory; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getItem($key) |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->pool->getItem($key); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getItems(array $keys = []) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->pool->getItems($keys); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function hasItem($key) |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->pool->hasItem($key); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function deleteItem($key) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->inMemory->deleteMulti([$key]); |
|
58
|
|
|
|
|
59
|
|
|
return $this->pool->deleteItem($key); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function deleteItems(array $keys) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->inMemory->deleteMulti($keys); |
|
65
|
|
|
|
|
66
|
|
|
return $this->pool->deleteItems($keys); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function invalidateTags(array $tags) |
|
70
|
|
|
{ |
|
71
|
|
|
// No tracking of tags in in-memory, as it's anyway meant to only optimize for reads (GETs) and not writes. |
|
72
|
|
|
$this->inMemory->clear(); |
|
73
|
|
|
|
|
74
|
|
|
return $this->pool->invalidateTags($tags); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function clear() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->inMemory->clear(); |
|
80
|
|
|
|
|
81
|
|
|
return $this->pool->clear(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function save(CacheItemInterface $item) |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->pool->save($item); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function saveDeferred(CacheItemInterface $item) |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->pool->saveDeferred($item); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function commit() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->pool->commit(); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|