From 968e839d59059dc4b5d3fd1fb27c4d32040261b5 Mon Sep 17 00:00:00 2001 From: Nikita Hovratov Date: Sat, 30 Mar 2024 19:31:29 +0100 Subject: [PATCH] [BUGFIX] Invalidate backend preview caches on each DataHandler operation Fixes: #171 --- Classes/Backend/Preview/PageLayout.php | 2 +- Classes/Backend/Preview/PreviewRenderer.php | 2 +- .../DataHandler/ClearBackendPreviewCaches.php | 39 +++++++++++++++++++ Configuration/Services.yaml | 3 ++ ext_localconf.php | 6 ++- 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 Classes/DataHandler/ClearBackendPreviewCaches.php diff --git a/Classes/Backend/Preview/PageLayout.php b/Classes/Backend/Preview/PageLayout.php index 86b298bb..ff38b15e 100644 --- a/Classes/Backend/Preview/PageLayout.php +++ b/Classes/Backend/Preview/PageLayout.php @@ -156,7 +156,7 @@ protected function getContentBlockData( if ($resolvedData->resolved !== $pageRow) { try { $exported = 'return ' . VarExporter::export($resolvedData) . ';'; - $this->cache->set($cacheIdentifier, $exported); + $this->cache->set($cacheIdentifier, $exported, ['content_blocks_preview'], 0); } catch (NotInstantiableTypeException) { // @todo objects of class TYPO3\CMS\Core\Resource\File can't be exported // @todo due to attached storage, which itself has EventDispatcher attached diff --git a/Classes/Backend/Preview/PreviewRenderer.php b/Classes/Backend/Preview/PreviewRenderer.php index 4fa36bcf..5a6a1c9a 100644 --- a/Classes/Backend/Preview/PreviewRenderer.php +++ b/Classes/Backend/Preview/PreviewRenderer.php @@ -83,7 +83,7 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string if ($resolvedData->resolved !== $record) { try { $exported = 'return ' . VarExporter::export($resolvedData) . ';'; - $this->cache->set($cacheIdentifier, $exported); + $this->cache->set($cacheIdentifier, $exported, ['content_blocks_preview'], 0); } catch (NotInstantiableTypeException) { // @todo objects of class TYPO3\CMS\Core\Resource\File can't be exported // @todo due to attached storage, which itself has EventDispatcher attached diff --git a/Classes/DataHandler/ClearBackendPreviewCaches.php b/Classes/DataHandler/ClearBackendPreviewCaches.php new file mode 100644 index 00000000..867f151e --- /dev/null +++ b/Classes/DataHandler/ClearBackendPreviewCaches.php @@ -0,0 +1,39 @@ +cacheManager->flushCachesByTag('content_blocks_preview'); + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 5b2b67d3..edbcb2da 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -14,6 +14,9 @@ services: TYPO3\CMS\ContentBlocks\Cache\InitializeContentBlockCache: public: true + TYPO3\CMS\ContentBlocks\DataHandler\ClearBackendPreviewCaches: + public: true + # @todo change to BeforeTcaOverridesEvent for v13 TYPO3\CMS\ContentBlocks\Generator\TcaGenerator: public: true diff --git a/ext_localconf.php b/ext_localconf.php index 3d64c020..e0324faf 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -2,6 +2,8 @@ defined('TYPO3') or die(); +use TYPO3\CMS\ContentBlocks\DataHandler\ClearBackendPreviewCaches; +use TYPO3\CMS\Core\Cache\Backend\FileBackend; use TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend; use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; @@ -44,11 +46,13 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['content_blocks_preview'] = [ 'frontend' => PhpFrontend::class, - 'backend' => SimpleFileBackend::class, + 'backend' => FileBackend::class, 'options' => [ 'defaultLifetime' => 0, ], 'groups' => ['system'], ]; +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = ClearBackendPreviewCaches::class; + $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['cb'][] = 'TYPO3\\CMS\\ContentBlocks\\ViewHelpers';