From 779a4ddb306db29c27108e4cb28e1eb7e8b0e19c Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 30 Aug 2024 16:51:16 +0200 Subject: [PATCH] Make the `always_expire_wfd_meta_resources` config setting work regardless of `kernel.debug` mode --- src/Config/CacheBustingResourceChecker.php | 19 ------------------- src/Config/WfdMetaConfigCache.php | 9 ++++++++- src/Config/WfdMetaConfigCacheFactory.php | 7 +++++-- .../WebfactoryWfdMetaExtension.php | 4 +--- src/Resources/config/services.xml | 1 + 5 files changed, 15 insertions(+), 25 deletions(-) delete mode 100644 src/Config/CacheBustingResourceChecker.php diff --git a/src/Config/CacheBustingResourceChecker.php b/src/Config/CacheBustingResourceChecker.php deleted file mode 100644 index a5bc270..0000000 --- a/src/Config/CacheBustingResourceChecker.php +++ /dev/null @@ -1,19 +0,0 @@ -file = $file; $this->innerCache = $innerCache; $this->metaQueryFactory = $metaQueryFactory; + $this->alwaysExpireWfdMetaResources = $alwaysExpire; } public function getPath(): string @@ -62,6 +65,10 @@ public function isWfdMetaFresh(): bool return true; } + if ($this->alwaysExpireWfdMetaResources) { + return false; + } + $metaQuery = $this->metaQueryFactory->create(); foreach ($wfdMetaResources['resources'] as $wfdMetaResource) { diff --git a/src/Config/WfdMetaConfigCacheFactory.php b/src/Config/WfdMetaConfigCacheFactory.php index 02d57b4..be55251 100644 --- a/src/Config/WfdMetaConfigCacheFactory.php +++ b/src/Config/WfdMetaConfigCacheFactory.php @@ -34,11 +34,14 @@ class WfdMetaConfigCacheFactory implements ConfigCacheFactoryInterface */ private $lockFactory; - public function __construct(ConfigCacheFactoryInterface $configCacheFactory, MetaQueryFactory $metaQueryFactory, LockFactory $lockFactory) + private bool $alwaysExpireWfdMetaResources; + + public function __construct(ConfigCacheFactoryInterface $configCacheFactory, MetaQueryFactory $metaQueryFactory, LockFactory $lockFactory, bool $alwaysExpireWfdMetaResources = false) { $this->configCacheFactory = $configCacheFactory; $this->metaQueryFactory = $metaQueryFactory; $this->lockFactory = $lockFactory; + $this->alwaysExpireWfdMetaResources = $alwaysExpireWfdMetaResources; } public function cache($file, $callback): ConfigCacheInterface @@ -70,7 +73,7 @@ public function cache($file, $callback): ConfigCacheInterface private function createCache($file, ConfigCacheInterface $innerCache): ConfigCacheInterface { - return new WfdMetaConfigCache($file, $innerCache, $this->metaQueryFactory); + return new WfdMetaConfigCache($file, $innerCache, $this->metaQueryFactory, $this->alwaysExpireWfdMetaResources); } private function fillCache($callback, ConfigCacheInterface $cache): void diff --git a/src/DependencyInjection/WebfactoryWfdMetaExtension.php b/src/DependencyInjection/WebfactoryWfdMetaExtension.php index 7629b76..fe38e39 100644 --- a/src/DependencyInjection/WebfactoryWfdMetaExtension.php +++ b/src/DependencyInjection/WebfactoryWfdMetaExtension.php @@ -33,8 +33,6 @@ public function load(array $configs, ContainerBuilder $container): void $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - if ($config['always_expire_wfd_meta_resources']) { - $yamlLoader->load('cache_busting.yml'); - } + $container->setParameter('webfactory_wfd_meta.always_expire_wfd_meta_resources', $config['always_expire_wfd_meta_resources']); } } diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 242a89f..ec7ec53 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -50,6 +50,7 @@ + %webfactory_wfd_meta.always_expire_wfd_meta_resources