Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions Classes/Cache/Backend/ReverseProxyCacheBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +33,7 @@
class ReverseProxyCacheBackend extends Typo3DatabaseBackend
{
use LoggerAwareTrait;
protected ProxyProviderInterface $reverseProxyProvider;
protected ?ProxyProviderInterface $reverseProxyProvider = null;
protected ?FrontendInterface $frontend = null;

/**
Expand All @@ -50,16 +51,25 @@ 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.
*/
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();
}
Expand All @@ -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]);
}
}
}
Expand All @@ -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));
Expand All @@ -108,7 +118,7 @@ public function flushByTags(array $tags): void
$urls = array_unique($urls);

if ($urls !== []) {
$this->reverseProxyProvider->flushCacheForUrls($urls);
$this->getReverseProxyProvider()->flushCacheForUrls($urls);
}
}

Expand Down
4 changes: 0 additions & 4 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
Loading