Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

AbstractHandler.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Cache;
8
9 use Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface;
10 use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
11 use Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierSanitizer;
12 use Ibexa\Core\Persistence\Cache\LocationPathConverter;
13 use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
14
20 abstract class AbstractHandler
21 {
23 protected $cache;
24
26 protected $persistenceHandler;
27
29 protected $logger;
30
32 protected $cacheIdentifierGenerator;
33
35 protected $cacheIdentifierSanitizer;
36
38 protected $locationPathConverter;
39
50 public function __construct(
51 TagAwareAdapterInterface $cache,
52 PersistenceHandler $persistenceHandler,
53 PersistenceLogger $logger,
54 CacheIdentifierGeneratorInterface $cacheIdentifierGenerator,
55 CacheIdentifierSanitizer $cacheIdentifierSanitizer,
56 LocationPathConverter $locationPathConverter
57 ) {
58 $this->cache = $cache;
59 $this->persistenceHandler = $persistenceHandler;
60 $this->logger = $logger;
61 $this->cacheIdentifierGenerator = $cacheIdentifierGenerator;
62 $this->cacheIdentifierSanitizer = $cacheIdentifierSanitizer;
63 $this->locationPathConverter = $locationPathConverter;
64 }
65
84 final protected function getMultipleCacheItems(
85 array $ids,
86 string $keyPrefix,
87 callable $missingLoader,
88 callable $loadedTagger,
89 array $keySuffixes = []
90 ): array {
91 if (empty($ids)) {
92 return [];
93 }
94
95 // Generate unique cache keys
96 $cacheKeys = [];
97 $cacheKeysToIdMap = [];
98 foreach (\array_unique($ids) as $id) {
99 $key = $keyPrefix . $id . ($keySuffixes[$id] ?? '');
100 $cacheKeys[] = $key;
101 $cacheKeysToIdMap[$key] = $id;
102 }
103
104 // Load cache items by cache keys (will contain hits and misses)
105 $list = [];
106 $cacheMisses = [];
107 foreach ($this->cache->getItems($cacheKeys) as $key => $cacheItem) {
108 $id = $cacheKeysToIdMap[$key];
109 if ($cacheItem->isHit()) {
110 $list[$id] = $cacheItem->get();
111 } else {
112 $cacheMisses[] = $id;
113 $list[$id] = $cacheItem;
114 }
115 }
116
117 // No misses, return completely cached list
118 if (empty($cacheMisses)) {
119 return $list;
120 }
121
122 // Load missing items, save to cache & apply to list if found
123 $loadedList = $missingLoader($cacheMisses);
124 foreach ($cacheMisses as $id) {
125 if (isset($loadedList[$id])) {
126 $this->cache->save(
127 $list[$id]
128 ->set($loadedList[$id])
129 ->tag($loadedTagger($loadedList[$id]))
130 );
131 $list[$id] = $loadedList[$id];
132 } else {
133 unset($list[$id]);
134 }
135 }
136
137 return $list;
138 }
139 }
Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierSanitizer
Definition: CacheIdentifierSanitizer.php:15
Ibexa\Core\Persistence\Cache\LocationPathConverter
Definition: LocationPathConverter.php:15
eZ\Publish\Core\Persistence\Cache\AbstractHandler
Class AbstractHandler.
Definition: AbstractHandler.php:21
eZ\Publish\Core\Persistence\Cache\AbstractHandler\$cache
$cache
Definition: AbstractHandler.php:23
eZ\Publish\Core\Persistence\Cache\AbstractHandler\__construct
__construct(TagAwareAdapterInterface $cache, PersistenceHandler $persistenceHandler, PersistenceLogger $logger, CacheIdentifierGeneratorInterface $cacheIdentifierGenerator, CacheIdentifierSanitizer $cacheIdentifierSanitizer, LocationPathConverter $locationPathConverter)
Setups current handler with everything needed.
Definition: AbstractHandler.php:50
eZ\Publish\Core\Persistence\Cache\AbstractHandler\$cacheIdentifierGenerator
$cacheIdentifierGenerator
Definition: AbstractHandler.php:32
eZ\Publish\Core\Persistence\Cache\AbstractHandler\$cacheIdentifierSanitizer
$cacheIdentifierSanitizer
Definition: AbstractHandler.php:35
eZ\Publish\Core\Persistence\Cache\AbstractHandler\$logger
$logger
Definition: AbstractHandler.php:29
eZ\Publish\Core\Persistence\Cache\AbstractHandler\$locationPathConverter
$locationPathConverter
Definition: AbstractHandler.php:38
eZ\Publish\Core\Persistence\Cache\AbstractHandler\getMultipleCacheItems
getMultipleCacheItems(array $ids, string $keyPrefix, callable $missingLoader, callable $loadedTagger, array $keySuffixes=[])
Helper for getting multiple cache items in one call and do the id extraction for you.
Definition: AbstractHandler.php:84
eZ\Publish\Core\Persistence\Cache\AbstractHandler\$persistenceHandler
$persistenceHandler
Definition: AbstractHandler.php:26
eZ\Publish\Core\Persistence\Cache\PersistenceLogger
Log un-cached & cached use of SPI Persistence.
Definition: PersistenceLogger.php:15
Ibexa\Core\Persistence\Cache\Identifier\CacheIdentifierGeneratorInterface
Definition: CacheIdentifierGeneratorInterface.php:15
eZ\Publish\SPI\Persistence\Handler
The main handler for Storage Engine.
Definition: SPI/Persistence/Handler.php:15
eZ\Publish\Core\Persistence\Cache
Definition: AbstractHandler.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.