Skip to content

Commit 1ebec48

Browse files
authored
Merge pull request #3 from Flowpack/update-neos
TASK: allow neos 7.3, add cache identifier prefix
2 parents 344b17a + f2e2ed4 commit 1ebec48

3 files changed

Lines changed: 31 additions & 18 deletions

File tree

Classes/NodeRendering/Dto/DocumentNodeCacheKey.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function redisKeyName(): string
5757
return preg_replace('/[^a-zA-Z0-9-]/', '_', sprintf('doc--%s-%s-%s', $this->nodeIdentifier, json_encode($this->dimensions), json_encode($this->arguments)));
5858
}
5959

60-
public function fullyQualifiedRedisKeyName(): string
60+
public function fullyQualifiedRedisKeyName(string $identifierPrefix): string
6161
{
62-
return 'Neos_Fusion_Content:entry:' . $this->redisKeyName();
62+
return $identifierPrefix . 'Neos_Fusion_Content:entry:' . $this->redisKeyName();
6363
}
64-
}
64+
}

Classes/NodeRendering/Infrastructure/RedisContentCacheReader.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Flowpack\DecoupledContentStore\NodeRendering\Dto\DocumentNodeCacheKey;
66
use Flowpack\DecoupledContentStore\NodeRendering\Dto\DocumentNodeCacheValues;
77
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderedDocumentFromContentCache;
8+
use Neos\Cache\Backend\AbstractBackend;
89
use Neos\Cache\Frontend\StringFrontend;
910
use Neos\Flow\Annotations as Flow;
1011
use Flowpack\DecoupledContentStore\Core\Infrastructure\RedisClientManager;
@@ -29,12 +30,22 @@ class RedisContentCacheReader
2930
*/
3031
protected $contentCache;
3132

33+
/**
34+
* @Flow\InjectConfiguration(path="cache.applicationIdentifier", package="Neos.Flow")
35+
* @var string
36+
*/
37+
protected $applicationIdentifier;
38+
3239
public function tryToExtractRenderingForEnumeratedNodeFromContentCache(DocumentNodeCacheKey $documentNodeCacheKey): RenderedDocumentFromContentCache
3340
{
3441
$maxNestLevel = ContentCache::MAXIMUM_NESTING_LEVEL;
3542
$contentCacheStartToken = ContentCache::CACHE_SEGMENT_START_TOKEN;
3643
$contentCacheEndToken = ContentCache::CACHE_SEGMENT_END_TOKEN;
3744
$contentCacheMarker = ContentCache::CACHE_SEGMENT_MARKER;
45+
/**
46+
* @see AbstractBackend::setCache()
47+
*/
48+
$identifierPrefix = md5($this->applicationIdentifier) . ':';
3849

3950
$redis = null;
4051
$backend = $this->contentCache->getBackend();
@@ -45,15 +56,16 @@ public function tryToExtractRenderingForEnumeratedNodeFromContentCache(DocumentN
4556
} else {
4657
throw new \RuntimeException('TODO: Cache backend must be OptimizedRedisCacheBackend.');
4758
}
48-
$serializedCacheValues = $redis->get($documentNodeCacheKey->fullyQualifiedRedisKeyName());
59+
$serializedCacheValues = $redis->get($documentNodeCacheKey->fullyQualifiedRedisKeyName($identifierPrefix));
4960
if ($serializedCacheValues === false) {
5061
return RenderedDocumentFromContentCache::createIncomplete('No Redis Key "' . $documentNodeCacheKey->redisKeyName() . '" found.');
5162
}
5263
$documentNodeCacheValues = DocumentNodeCacheValues::fromJsonString($serializedCacheValues);
5364

5465
$script = "
5566
local rootIdentifier = ARGV[1]
56-
67+
local identifierPrefix = ARGV[2]
68+
5769
local function readContentCacheRecursively(identifier, depth)
5870
depth = depth or 1
5971
@@ -62,45 +74,45 @@ public function tryToExtractRenderingForEnumeratedNodeFromContentCache(DocumentN
6274
return '', 'Maximum Nesting Level Reached'
6375
end
6476
65-
local content = redis.call('GET', 'Neos_Fusion_Content:entry:' .. identifier)
77+
local content = redis.call('GET', identifierPrefix .. 'Neos_Fusion_Content:entry:' .. identifier)
6678
if not content then
67-
return '', 'Neos_Fusion_Content:entry:' .. identifier .. ' not found'
79+
return '', identifierPrefix .. 'Neos_Fusion_Content:entry:' .. identifier .. ' not found'
6880
end
6981
70-
local error = nil
82+
local error = nil
7183
content = string.gsub(content, '${contentCacheStartToken}${contentCacheMarker}([a-z0-9]+)${contentCacheEndToken}${contentCacheMarker}', function(id)
7284
local str
7385
local errMsg
7486
str, errMsg = readContentCacheRecursively(id, depth + 1)
75-
87+
7688
if errMsg then
7789
error = errMsg
7890
end
79-
91+
8092
return str
8193
end
8294
)
83-
95+
8496
if error then
8597
return nil, error
8698
else
8799
return content, nil
88100
end
89101
end
90-
102+
91103
local content, error = readContentCacheRecursively(rootIdentifier)
92104
if not error then
93105
error = ''
94106
end
95-
107+
96108
if not content then
97109
content = ''
98110
end
99-
111+
100112
return {content, error}
101113
";
102114
// starting with Lua 7, eval_ro can be used.
103-
$res = $redis->eval($script, [$documentNodeCacheValues->getRootIdentifier()], 0);
115+
$res = $redis->eval($script, [$documentNodeCacheValues->getRootIdentifier(), $identifierPrefix], 0);
104116
$error = $redis->getLastError();
105117
if ($error !== null) {
106118
throw new \RuntimeException('Redis Error: ' . $error);
@@ -117,4 +129,4 @@ public function tryToExtractRenderingForEnumeratedNodeFromContentCache(DocumentN
117129
}
118130
return RenderedDocumentFromContentCache::createWithFullContent($content, $documentNodeCacheValues);
119131
}
120-
}
132+
}

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"name": "flowpack/decoupledcontentstore",
55
"require": {
66
"php": "^7.1",
7-
"neos/neos": "~7.1.0",
8-
"albertofem/rsync-lib": "~1.0"
7+
"neos/neos": "^7.0",
8+
"albertofem/rsync-lib": "~1.0",
9+
"sandstorm/optimizedrediscachebackend": "^1.1.4"
910
},
1011
"autoload": {
1112
"psr-4": {

0 commit comments

Comments
 (0)