Skip to content

Commit 3baadfe

Browse files
committed
OXDEV-10239 Fix template chain cache invalidation on cache clear
1 parent e2e68e7 commit 3baadfe

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

CHANGELOG-2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
### Fixed
1515
- Rendering template extensions for module templates
16+
- Invalidate template chain cache on shop cache clear
1617

1718
### Deprecated
1819
- Node `$tag` constructor parameter

src/Event/InvalidateTemplateChainCacheEventSubscriber.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OxidEsales\Twig\Event;
1111

12+
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Event\ClearShopCacheEvent;
1213
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Event\ModuleConfigurationChangedEvent;
1314
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Event\FinalizingModuleActivationEvent;
1415
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Event\FinalizingModuleDeactivationEvent;
@@ -25,7 +26,7 @@ public function __construct(private readonly TemplateChainCacheInterface $templa
2526
}
2627

2728
public function invalidateTemplateChainCache(
28-
ModuleSetupEvent|ModuleConfigurationChangedEvent|ThemeSettingChangedEvent|ThemeActivatedEvent $event
29+
ModuleSetupEvent|ModuleConfigurationChangedEvent|ThemeSettingChangedEvent|ThemeActivatedEvent|ClearShopCacheEvent $event
2930
): void
3031
{
3132
$this->templateChainCache->invalidate($event->getShopId());
@@ -39,6 +40,7 @@ public static function getSubscribedEvents(): array
3940
ModuleConfigurationChangedEvent::class => 'invalidateTemplateChainCache',
4041
ThemeSettingChangedEvent::class => 'invalidateTemplateChainCache',
4142
ThemeActivatedEvent::class => 'invalidateTemplateChainCache',
43+
ClearShopCacheEvent::class => 'invalidateTemplateChainCache',
4244
];
4345
}
4446
}

tests/Integration/Event/InvalidateTemplateChainCacheEventSubscriberTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OxidEsales\Twig\Tests\Integration\Event;
1111

12+
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Event\ClearShopCacheEvent;
1213
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
1314
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Event\ModuleConfigurationChangedEvent;
1415
use OxidEsales\EshopCommunity\Internal\Framework\Theme\Event\ThemeSettingChangedEvent;
@@ -89,6 +90,19 @@ public function testThemeActivatedEventInvalidatesTemplateChainCache(): void
8990
$this->cache->get(self::TEMPLATE_NAME);
9091
}
9192

93+
public function testClearShopCacheEventInvalidatesTemplateChainCache(): void
94+
{
95+
$this->putCacheEntry();
96+
97+
$this->eventDispatcher->dispatch(
98+
new ClearShopCacheEvent($this->shopId)
99+
);
100+
101+
$this->expectException(TemplateChainCacheNotFoundException::class);
102+
103+
$this->cache->get(self::TEMPLATE_NAME);
104+
}
105+
92106
private function putCacheEntry(): void
93107
{
94108
$this->cache->put(

0 commit comments

Comments
 (0)