|
22 | 22 | use Neos\Flow\Utility\Environment;
|
23 | 23 | use Neos\Utility\Files;
|
24 | 24 | use Neos\Flow\Utility\PhpAnalyzer;
|
| 25 | +use Neos\Cache\Psr\Cache\CachePool; |
| 26 | +use Neos\Cache\Psr\SimpleCache\SimpleCache; |
25 | 27 | use Psr\Log\LoggerInterface;
|
| 28 | +use Psr\SimpleCache\CacheInterface; |
| 29 | +use Psr\Cache\CacheItemPoolInterface; |
26 | 30 |
|
27 | 31 | /**
|
28 | 32 | * The Cache Manager
|
@@ -53,10 +57,20 @@ class CacheManager
|
53 | 57 | protected $environment;
|
54 | 58 |
|
55 | 59 | /**
|
56 |
| - * @var array |
| 60 | + * @var FrontendInterface[] |
57 | 61 | */
|
58 | 62 | protected $caches = [];
|
59 | 63 |
|
| 64 | + /** |
| 65 | + * @var CacheInterface[] |
| 66 | + */ |
| 67 | + protected $simpleCaches = []; |
| 68 | + |
| 69 | + /** |
| 70 | + * @var CacheItemPoolInterface[] |
| 71 | + */ |
| 72 | + protected $cacheItemPools = []; |
| 73 | + |
60 | 74 | /**
|
61 | 75 | * @var array
|
62 | 76 | */
|
@@ -180,6 +194,42 @@ public function getCache(string $identifier): FrontendInterface
|
180 | 194 | return $this->caches[$identifier];
|
181 | 195 | }
|
182 | 196 |
|
| 197 | + /** |
| 198 | + * Return a SimpleCache frontend for the cache specified by $identifier |
| 199 | + * |
| 200 | + * @param string $identifier |
| 201 | + * @return CacheInterface |
| 202 | + */ |
| 203 | + public function getSimpleCache(string $identifier): CacheInterface |
| 204 | + { |
| 205 | + if (isset($this->simpleCaches[$identifier])) { |
| 206 | + return $this->simpleCaches[$identifier]; |
| 207 | + } |
| 208 | + |
| 209 | + $cache = $this->getCache($identifier); |
| 210 | + $simpleCache = new SimpleCache($identifier, $cache->getBackend()); |
| 211 | + $this->simpleCaches[$identifier] = $simpleCache; |
| 212 | + return $simpleCache; |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Return a SimpleCache frontend for the cache specified by $identifier |
| 217 | + * |
| 218 | + * @param string $identifier |
| 219 | + * @return CacheItemPoolInterface |
| 220 | + */ |
| 221 | + public function getCacheItemPool(string $identifier): CacheItemPoolInterface |
| 222 | + { |
| 223 | + if (isset($this->cacheItemPools[$identifier])) { |
| 224 | + return $this->cacheItemPools[$identifier]; |
| 225 | + } |
| 226 | + |
| 227 | + $cache = $this->getCache($identifier); |
| 228 | + $cacheItemPool = new CachePool($identifier, $cache->getBackend()); |
| 229 | + $this->cacheItemPools[$identifier] = $cacheItemPool; |
| 230 | + return $cacheItemPool; |
| 231 | + } |
| 232 | + |
183 | 233 | /**
|
184 | 234 | * Checks if the specified cache has been registered.
|
185 | 235 | *
|
|
0 commit comments