flow-development-collection icon indicating copy to clipboard operation
flow-development-collection copied to clipboard

TASK: Make $environmentConfiguration of AbstractBackend not optional

Open mhsdesign opened this issue 6 months ago • 0 comments

... because it will always be provided via the cache factory:

new $backendObjectName($environmentConfiguration, $backendOptions);

the only case where a cache backend is independent of the environment is the transient backend where It's still impossible due to the hard coded instantiation to have it actually decoupled from the $environmentConfiguration, see draft:

From 9ad5aed81dd5faae3b05b68798bffbabea714b7d Mon Sep 17 00:00:00 2001
From: mhsdesign <[email protected]>
Date: Thu, 10 Apr 2025 14:14:46 +0200
Subject: [PATCH] TASK:
 rabbit-hole-TransientMemoryBackend-independant-of-EnvironmentConfiguration

i did this to make `EnvironmentConfiguration` not nullable as we dont need this only not in the TransientMemoryBackend.

But cache factory instantiates the stuff either way with both ...
---
 .../Classes/Backend/AbstractBackend.php       |  5 ++--
 .../Backend/TransientMemoryBackend.php        | 25 ++++++++++++++++++-
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/Neos.Cache/Classes/Backend/AbstractBackend.php b/Neos.Cache/Classes/Backend/AbstractBackend.php
index 34101f3ef8..99b4afbf99 100644
--- a/Neos.Cache/Classes/Backend/AbstractBackend.php
+++ b/Neos.Cache/Classes/Backend/AbstractBackend.php
@@ -57,11 +57,10 @@ abstract class AbstractBackend implements BackendInterface
     /**
      * Constructs this backend
      *
-     * @param EnvironmentConfiguration $environmentConfiguration
      * @param array<string,mixed> $options Configuration options - depends on the actual backend
      * @api
      */
-    public function __construct(?EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
+    public function __construct(EnvironmentConfiguration $environmentConfiguration = null, array $options = [])
     {
         $this->environmentConfiguration = $environmentConfiguration;
 
@@ -115,7 +114,7 @@ public function setCache(FrontendInterface $cache): void
     {
         $this->cache = $cache;
         $this->cacheIdentifier = $this->cache->getIdentifier();
-        $applicationIdentifier = $this->environmentConfiguration instanceof EnvironmentConfiguration ? $this->environmentConfiguration->getApplicationIdentifier() : '';
+        $applicationIdentifier = $this->environmentConfiguration->getApplicationIdentifier();
         $this->identifierPrefix = md5($applicationIdentifier) . ':' . $this->cacheIdentifier . ':';
     }
 
diff --git a/Neos.Cache/Classes/Backend/TransientMemoryBackend.php b/Neos.Cache/Classes/Backend/TransientMemoryBackend.php
index 1ea561187c..8bceea8ab8 100644
--- a/Neos.Cache/Classes/Backend/TransientMemoryBackend.php
+++ b/Neos.Cache/Classes/Backend/TransientMemoryBackend.php
@@ -22,8 +22,14 @@
  *
  * @api
  */
-class TransientMemoryBackend extends IndependentAbstractBackend implements TaggableBackendInterface
+class TransientMemoryBackend implements TaggableBackendInterface
 {
+    /**
+     * Reference to the cache frontend which uses this backend
+     * @var FrontendInterface
+     */
+    protected $cache;
+
     /**
      * @var array
      */
@@ -34,6 +40,12 @@ class TransientMemoryBackend extends IndependentAbstractBackend implements Tagga
      */
     protected $tagsAndEntries = [];
 
+    // todo there is no real contract it will just be invoked with the env configuration and options .. :(
+    public function __construct()
+    {
+
+    }
+
     /**
      * Saves data in the cache.
      *
@@ -175,4 +187,15 @@ public function flushByTags(array $tags): int
     public function collectGarbage(): void
     {
     }
+
+    public function setCache(FrontendInterface $cache): void
+    {
+        $this->cache = $cache;
+    }
+
+    public function getPrefixedIdentifier(string $entryIdentifier): string
+    {
+        $identifierPrefix = $this->cache->getIdentifier() . ':';
+        return $identifierPrefix . $entryIdentifier;
+    }
 }

mhsdesign avatar Apr 18 '25 06:04 mhsdesign