From 9f593b38e762c67c85b498cc372214b1b491a122 Mon Sep 17 00:00:00 2001 From: Lars Lauger Date: Mon, 22 Feb 2021 15:14:57 +0100 Subject: [PATCH 1/3] BUGFIX: Use ContentCacheFlusher Aspect for banning varnish pages The cache tags of the Neos ContentCacheFlusher are now used instead of the manually generated ones from the ContentCacheFlusherService Resolves #55 --- Classes/Aspects/ContentCacheAspect.php | 31 ++++++++++++++++++++++++++ Classes/Package.php | 30 ------------------------- 2 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 Classes/Package.php diff --git a/Classes/Aspects/ContentCacheAspect.php b/Classes/Aspects/ContentCacheAspect.php index 494d1d5..d148d6f 100644 --- a/Classes/Aspects/ContentCacheAspect.php +++ b/Classes/Aspects/ContentCacheAspect.php @@ -3,6 +3,8 @@ namespace MOC\Varnish\Aspects; +use MOC\Varnish\Service\CacheTagService; +use MOC\Varnish\Service\VarnishBanService; use Neos\Flow\Annotations as Flow; use Neos\Flow\Aop\JoinPointInterface; use Neos\Flow\Configuration\Exception\InvalidConfigurationException; @@ -30,6 +32,18 @@ class ContentCacheAspect */ protected $logger; + /** + * @Flow\Inject + * @var VarnishBanService + */ + protected $varnishBanService; + + /** + * @Flow\Inject + * @var CacheTagService + */ + protected $cacheTagService; + /** * @var bool */ @@ -106,6 +120,23 @@ public function registerDisableContentCache(JoinPointInterface $joinPoint): void } } + /** + * @Flow\Before("setting(MOC.Varnish.enabled) && method(Neos\Neos\Fusion\Cache\ContentCacheFlusher->shutdownObject())") + * @param JoinPointInterface $joinPoint + * + * @throws PropertyNotAccessibleException + */ + public function interceptContentCacheFlush(JoinPointInterface $joinPoint) + { + $object = $joinPoint->getProxy(); + + $tags = array_keys(ObjectAccess::getProperty($object, 'tagsToFlush', true)); + $tags = $this->cacheTagService->sanitizeTags($tags); + $tags = $this->cacheTagService->shortenTags($tags); + + $this->varnishBanService->banByTags($tags); + } + /** * @return bool true if an uncached segment was evaluated */ diff --git a/Classes/Package.php b/Classes/Package.php deleted file mode 100644 index df33bbf..0000000 --- a/Classes/Package.php +++ /dev/null @@ -1,30 +0,0 @@ -getSignalSlotDispatcher(); - $dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady', function (ConfigurationManager $configurationManager) use ($dispatcher) { - $enabled = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'MOC.Varnish.enabled'); - if ((boolean)$enabled === true) { - $dispatcher->connect(PublishingService::class, 'nodePublished', ContentCacheFlusherService::class, 'flushForNode'); - } - }); - } -} From ad2a3aed76670fa7fe57ba3bcc3b593955f49347 Mon Sep 17 00:00:00 2001 From: Lars Lauger Date: Sun, 7 Mar 2021 17:17:56 +0100 Subject: [PATCH 2/3] TASK: Mark ContentCacheFlusherService as deprecated --- Classes/Service/ContentCacheFlusherService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Classes/Service/ContentCacheFlusherService.php b/Classes/Service/ContentCacheFlusherService.php index afbdcde..a87d79c 100644 --- a/Classes/Service/ContentCacheFlusherService.php +++ b/Classes/Service/ContentCacheFlusherService.php @@ -19,6 +19,8 @@ /** * @Flow\Scope("singleton") + * + * @deprecated will be removed with 6.0 */ class ContentCacheFlusherService { From fd4aee00a68d5f6a8645a3a14315f18612de58d2 Mon Sep 17 00:00:00 2001 From: Lars Lauger Date: Mon, 16 Aug 2021 16:28:04 +0200 Subject: [PATCH 3/3] BUGFIX: Don't shorten cache tags twice in ContentCacheAspect --- Classes/Aspects/ContentCacheAspect.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Classes/Aspects/ContentCacheAspect.php b/Classes/Aspects/ContentCacheAspect.php index d148d6f..f908d54 100644 --- a/Classes/Aspects/ContentCacheAspect.php +++ b/Classes/Aspects/ContentCacheAspect.php @@ -131,8 +131,6 @@ public function interceptContentCacheFlush(JoinPointInterface $joinPoint) $object = $joinPoint->getProxy(); $tags = array_keys(ObjectAccess::getProperty($object, 'tagsToFlush', true)); - $tags = $this->cacheTagService->sanitizeTags($tags); - $tags = $this->cacheTagService->shortenTags($tags); $this->varnishBanService->banByTags($tags); }