|
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
|
|
|
namespace eZ\Publish\Core\Persistence\Cache; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler; |
|
12
|
|
|
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class AbstractHandler. |
|
16
|
|
|
* |
|
17
|
|
|
* Abstract handler for use in other Persistence Cache Handlers. |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractHandler |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $cache; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var \eZ\Publish\SPI\Persistence\Handler |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $persistenceHandler; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var \eZ\Publish\Core\Persistence\Cache\PersistenceLogger |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $logger; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Setups current handler with everything needed. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $cache |
|
40
|
|
|
* @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
|
41
|
|
|
* @param \eZ\Publish\Core\Persistence\Cache\PersistenceLogger $logger |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
TagAwareAdapterInterface $cache, |
|
45
|
|
|
PersistenceHandler $persistenceHandler, |
|
46
|
|
|
PersistenceLogger $logger |
|
47
|
|
|
) { |
|
48
|
|
|
$this->cache = $cache; |
|
49
|
|
|
$this->persistenceHandler = $persistenceHandler; |
|
50
|
|
|
$this->logger = $logger; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Helper for getting multiple cache items. |
|
55
|
|
|
* |
|
56
|
|
|
* @param array $ids |
|
57
|
|
|
* @param string $keyPrefix |
|
58
|
|
|
* |
|
59
|
|
|
* @return array 2 arrays returned as [$cacheMissIds, $list], where list contains objects / cache misses, key by id. |
|
60
|
|
|
*/ |
|
61
|
|
|
final protected function getMultipleCacheItems(array $ids, string $keyPrefix) : array |
|
62
|
|
|
{ |
|
63
|
|
|
if (empty($ids)) { |
|
64
|
|
|
return [[], []]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$cacheKeys = []; |
|
68
|
|
|
foreach (array_unique($ids) as $id) { |
|
69
|
|
|
$cacheKeys[] = $keyPrefix.$id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$list = []; |
|
73
|
|
|
$cacheMissIds = []; |
|
74
|
|
|
$keyPrefixLength = strlen($keyPrefix); |
|
75
|
|
|
foreach($this->cache->getItems($cacheKeys) as $key => $cacheItem) { |
|
76
|
|
|
$id = substr($key, $keyPrefixLength); |
|
77
|
|
|
if ($cacheItem->isHit()) { |
|
78
|
|
|
$list[$id] = $cacheItem->get(); |
|
79
|
|
|
continue; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$cacheMissIds[] = $id; |
|
83
|
|
|
$list[$id] = $cacheItem; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return [$cacheMissIds, $list]; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|