55use Flowpack \DecoupledContentStore \NodeRendering \Dto \DocumentNodeCacheKey ;
66use Flowpack \DecoupledContentStore \NodeRendering \Dto \DocumentNodeCacheValues ;
77use Flowpack \DecoupledContentStore \NodeRendering \Dto \RenderedDocumentFromContentCache ;
8+ use Neos \Cache \Backend \AbstractBackend ;
89use Neos \Cache \Frontend \StringFrontend ;
910use Neos \Flow \Annotations as Flow ;
1011use 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+ }
0 commit comments