diff --git a/Classes/Cache/Backend/ReverseProxyCacheBackend.php b/Classes/Cache/Backend/ReverseProxyCacheBackend.php index 582f6fa..c6c42d6 100755 --- a/Classes/Cache/Backend/ReverseProxyCacheBackend.php +++ b/Classes/Cache/Backend/ReverseProxyCacheBackend.php @@ -18,6 +18,7 @@ */ use B13\Proxycachemanager\Provider\ProxyProviderInterface; +use B13\Proxycachemanager\ProxyConfiguration; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; @@ -32,7 +33,7 @@ class ReverseProxyCacheBackend extends Typo3DatabaseBackend { use LoggerAwareTrait; - protected ProxyProviderInterface $reverseProxyProvider; + protected ?ProxyProviderInterface $reverseProxyProvider = null; protected ?FrontendInterface $frontend = null; /** @@ -50,6 +51,15 @@ public function setReverseProxyProvider(ProxyProviderInterface $reverseProxyProv $this->reverseProxyProvider = $reverseProxyProvider; } + /** + * The provider is resolved lazily instead of being passed as cache option, so no + * object instance needs to be stored in $GLOBALS['TYPO3_CONF_VARS']. + * */ + protected function getReverseProxyProvider(): ProxyProviderInterface + { + return $this->reverseProxyProvider ??= GeneralUtility::makeInstance(ProxyConfiguration::class)->getProxyProvider(); + } + /** * Removes all cache entries of this cache. * Also let the proxy provider know to clear everything as well. @@ -57,9 +67,9 @@ public function setReverseProxyProvider(ProxyProviderInterface $reverseProxyProv public function flush(): void { // make the HTTP Purge call - if ($this->reverseProxyProvider->isActive()) { + if ($this->getReverseProxyProvider()->isActive()) { $urls = $this->getAllCachedUrls(); - $this->reverseProxyProvider->flushAllUrls($urls); + $this->getReverseProxyProvider()->flushAllUrls($urls); } parent::flush(); } @@ -71,12 +81,12 @@ public function flush(): void */ public function flushByTag($tag): void { - if ($this->reverseProxyProvider->isActive()) { + if ($this->getReverseProxyProvider()->isActive()) { $identifiers = $this->findIdentifiersByTag($tag); foreach ($identifiers as $entryIdentifier) { $url = $this->resolveCachedUrl($entryIdentifier); if ($url !== null) { - $this->reverseProxyProvider->flushCacheForUrls([$url]); + $this->getReverseProxyProvider()->flushCacheForUrls([$url]); } } } @@ -91,7 +101,7 @@ public function flushByTag($tag): void */ public function flushByTags(array $tags): void { - if ($this->reverseProxyProvider->isActive()) { + if ($this->getReverseProxyProvider()->isActive()) { $identifiers = []; foreach ($tags as $tag) { $identifiers = array_merge($identifiers, $this->findIdentifiersByTag($tag)); @@ -108,7 +118,7 @@ public function flushByTags(array $tags): void $urls = array_unique($urls); if ($urls !== []) { - $this->reverseProxyProvider->flushCacheForUrls($urls); + $this->getReverseProxyProvider()->flushCacheForUrls($urls); } } diff --git a/ext_localconf.php b/ext_localconf.php index 172e14f..fa7e6c9 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -2,16 +2,12 @@ defined('TYPO3') or die(); -use B13\Proxycachemanager\ProxyConfiguration; -use TYPO3\CMS\Core\Utility\GeneralUtility; - if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_proxy'] ?? null)) { $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['tx_proxy'] = [ 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, 'backend' => \B13\Proxycachemanager\Cache\Backend\ReverseProxyCacheBackend::class, 'options' => [ 'defaultLifetime' => 0, // @todo: should be not "infinite" but rather set to whatever the proxy settings are - 'reverseProxyProvider' => (GeneralUtility::makeInstance(ProxyConfiguration::class))->getProxyProvider(), ], // setting the pages group makes sure that when the page cache is cleared, that this cache is cleared as well 'groups' => ['pages', 'proxy'],