Skip to content

Commit b774830

Browse files
committed
FEATURE: Add methods getSimpleCache and getCacheItemPool to the cacheManager
The methods create an PSR Frontend for the cache with the given identifier.
1 parent d559aca commit b774830

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

Neos.Flow/Classes/Cache/CacheManager.php

+51-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
use Neos\Flow\Utility\Environment;
2323
use Neos\Utility\Files;
2424
use Neos\Flow\Utility\PhpAnalyzer;
25+
use Neos\Cache\Psr\Cache\CachePool;
26+
use Neos\Cache\Psr\SimpleCache\SimpleCache;
2527
use Psr\Log\LoggerInterface;
28+
use Psr\SimpleCache\CacheInterface;
29+
use Psr\Cache\CacheItemPoolInterface;
2630

2731
/**
2832
* The Cache Manager
@@ -53,10 +57,20 @@ class CacheManager
5357
protected $environment;
5458

5559
/**
56-
* @var array
60+
* @var FrontendInterface[]
5761
*/
5862
protected $caches = [];
5963

64+
/**
65+
* @var CacheInterface[]
66+
*/
67+
protected $simpleCaches = [];
68+
69+
/**
70+
* @var CacheItemPoolInterface[]
71+
*/
72+
protected $cacheItemPools = [];
73+
6074
/**
6175
* @var array
6276
*/
@@ -180,6 +194,42 @@ public function getCache(string $identifier): FrontendInterface
180194
return $this->caches[$identifier];
181195
}
182196

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+
183233
/**
184234
* Checks if the specified cache has been registered.
185235
*

0 commit comments

Comments
 (0)