Skip to content

Commit a170dba

Browse files
committed
FEATURE: Make package work with Neos 7.3 & 8
With this change the RedisContentCacheReader uses the integrated redis backend with Neos 8 and the optimized Redis backend with Neos 7. An exception is thrown if neither condition is meet.
1 parent f235edb commit a170dba

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

Classes/NodeRendering/Infrastructure/RedisContentCacheReader.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
use Flowpack\DecoupledContentStore\NodeRendering\Dto\DocumentNodeCacheValues;
77
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderedDocumentFromContentCache;
88
use Neos\Cache\Backend\AbstractBackend;
9+
use Neos\Cache\Backend\RedisBackend;
910
use Neos\Cache\Frontend\StringFrontend;
1011
use Neos\Flow\Annotations as Flow;
11-
use Flowpack\DecoupledContentStore\Core\Infrastructure\RedisClientManager;
12+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
13+
use Neos\Flow\Package\PackageManager;
1214
use Neos\Fusion\Core\Cache\ContentCache;
13-
use Neos\Cache\Backend\RedisBackend;
1415

1516
/**
1617
* @Flow\Scope("singleton")
@@ -20,15 +21,15 @@ class RedisContentCacheReader
2021

2122
/**
2223
* @Flow\Inject
23-
* @var RedisClientManager
24+
* @var StringFrontend
2425
*/
25-
protected $redisClient;
26+
protected $contentCache;
2627

2728
/**
2829
* @Flow\Inject
29-
* @var StringFrontend
30+
* @var ObjectManagerInterface
3031
*/
31-
protected $contentCache;
32+
protected $objectManager;
3233

3334
/**
3435
* @Flow\InjectConfiguration(path="cache.applicationIdentifier", package="Neos.Flow")
@@ -47,14 +48,22 @@ public function tryToExtractRenderingForEnumeratedNodeFromContentCache(DocumentN
4748
*/
4849
$identifierPrefix = md5($this->applicationIdentifier) . ':';
4950

50-
$redis = null;
51+
$packageManager = $this->objectManager->get(PackageManager::class);
52+
$flowPackage = $packageManager->getPackage('Neos.Flow');
53+
preg_match('/^(\d+\.\d+)/', $flowPackage->getInstalledVersion(), $versionMatches);
54+
$flowMajorVersion = (int)($versionMatches[1] ?? '0');
55+
5156
$backend = $this->contentCache->getBackend();
52-
if ($backend instanceof RedisBackend) {
57+
if ($flowMajorVersion >= 8 && $backend instanceof RedisBackend) {
5358
$reflProp = new \ReflectionProperty(RedisBackend::class, 'redis');
5459
$reflProp->setAccessible(true);
5560
$redis = $reflProp->getValue($backend);
61+
} elseif (get_class($backend) === 'Sandstorm\OptimizedRedisCacheBackend\OptimizedRedisCacheBackend') {
62+
$reflProp = new \ReflectionProperty(\Sandstorm\OptimizedRedisCacheBackend\OptimizedRedisCacheBackend::class, 'redis');
63+
$reflProp->setAccessible(true);
64+
$redis = $reflProp->getValue($backend);
5665
} else {
57-
throw new \RuntimeException('TODO: Cache backend must be OptimizedRedisCacheBackend.');
66+
throw new \RuntimeException('The cache backend for "Neos_Fusion_Content" must be an OptimizedRedisCacheBackend, but is ' . get_class($backend), 1622570000);
5867
}
5968
$serializedCacheValues = $redis->get($documentNodeCacheKey->fullyQualifiedRedisKeyName($identifierPrefix));
6069
if ($serializedCacheValues === false) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ as the basis for orchestrating and executing a content release.
4747
## Requirements
4848

4949
- Redis
50-
- Sandstorm.OptimizedCacheBackend recommended
50+
- Sandstorm.OptimizedCacheBackend is required when this package is used with Neos 7.3 (Neos 8 already has an optimized Redis backend)
5151
- Prunner
5252

5353
Start up prunner via the following command:

0 commit comments

Comments
 (0)