diff --git a/INSTALL.md b/INSTALL.md index 0e7115a..e671196 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -118,3 +118,23 @@ rewrite "^/var/storage/packages/(.*)" "/var/storage/packages/$1" break; Last step, if you are on *nix operation system, is to make sure to run the appropriate command for setting correct folder permissions, you can find the information you need in [installation guide for eZ Platform](https://doc.ezplatform.com/en/latest/getting_started/install_ez_platform/). + +### Clearing of cache + +Legacy bridge will by default also clear SPI cache (stored in redis, memcached or disk) when content-view cache is +cleared in legacy. This behaviour can be disabled using the setting: + +``` +// app/config/ezplatform.yml +ez_publish_legacy: + clear_all_spi_cache_from_legacy: false +``` + +Legacy bridge will also alter the default behaviour of Symfony's `bin/console cache:clear` command so that SPI cache +is cleared when it is executed. This behaviour can be disabled using the setting: + +``` +// app/config/ezplatform.yml +ez_publish_legacy: + clear_all_spi_cache_on_symfony_clear_cache: false +``` diff --git a/bundle/Cache/PersistenceCachePurger.php b/bundle/Cache/PersistenceCachePurger.php index ae67da9..9766dd2 100644 --- a/bundle/Cache/PersistenceCachePurger.php +++ b/bundle/Cache/PersistenceCachePurger.php @@ -55,6 +55,16 @@ class PersistenceCachePurger implements CacheClearerInterface */ protected $allCleared = false; + /** + * @var bool + */ + private $clearAllSPICacheOnSymfonyClearCache; + + /** + * @var bool + */ + private $clearAllSPICacheFromLegacy; + /** * Setups current handler with everything needed. * @@ -65,21 +75,35 @@ class PersistenceCachePurger implements CacheClearerInterface public function __construct( TagAwareAdapterInterface $cache, LocationHandlerInterface $locationHandler, - CacheIdentifierGeneratorInterface $cacheIdentifierGenerator + CacheIdentifierGeneratorInterface $cacheIdentifierGenerator, + bool $clearAllSPICacheOnSymfonyClearCache = true, + bool $clearAllSPICacheFromLegacy = true ) { $this->cache = $cache; $this->locationHandler = $locationHandler; $this->cacheIdentifierGenerator = $cacheIdentifierGenerator; + $this->clearAllSPICacheOnSymfonyClearCache = $clearAllSPICacheOnSymfonyClearCache; + $this->clearAllSPICacheFromLegacy = $clearAllSPICacheFromLegacy; } /** - * Clear all persistence cache. + * Clear all persistence cache if that is allowed by config. * * In legacy kernel used when user presses clear all cache button in admin interface. + */ + public function all() + { + if ($this->clearAllSPICacheFromLegacy) { + $this->flushSPICache(); + } + } + + /** + * Clear all persistence cache. * * Sets a internal flag 'allCleared' to avoid clearing cache several times */ - public function all() + private function flushSPICache() { if ($this->isSwitchedOff()) { return; @@ -219,9 +243,11 @@ public function contentType($id = null) } if ($id === null) { - $this->cache->invalidateTags([ - $this->cacheIdentifierGenerator->generateTag(self::TYPE_MAP_IDENTIFIER), - ]); + if ($this->clearAllSPICacheFromLegacy) { + $this->cache->invalidateTags([ + $this->cacheIdentifierGenerator->generateTag(self::TYPE_MAP_IDENTIFIER), + ]); + } } elseif (is_scalar($id)) { $this->cache->invalidateTags([ $this->cacheIdentifierGenerator->generateTag(self::TYPE_IDENTIFIER, [$id]), @@ -358,6 +384,8 @@ public function user($id = null) */ public function clear($cacheDir) { - $this->all(); + if ($this->clearAllSPICacheOnSymfonyClearCache) { + $this->flushSPICache(); + } } } diff --git a/bundle/DependencyInjection/Configuration.php b/bundle/DependencyInjection/Configuration.php index cdc8f40..bda92b7 100644 --- a/bundle/DependencyInjection/Configuration.php +++ b/bundle/DependencyInjection/Configuration.php @@ -19,6 +19,8 @@ public function getConfigTreeBuilder() $rootNode ->children() ->booleanNode('enabled')->defaultTrue()->end() + ->booleanNode('clear_all_spi_cache_on_symfony_clear_cache')->defaultTrue()->end() + ->booleanNode('clear_all_spi_cache_from_legacy')->defaultTrue()->end() ->scalarNode('root_dir') ->validate() ->ifTrue( diff --git a/bundle/DependencyInjection/EzPublishLegacyExtension.php b/bundle/DependencyInjection/EzPublishLegacyExtension.php index 09989c4..827fc6c 100644 --- a/bundle/DependencyInjection/EzPublishLegacyExtension.php +++ b/bundle/DependencyInjection/EzPublishLegacyExtension.php @@ -38,6 +38,20 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('ezpublish_legacy.root_dir', $config['root_dir']); } + if (isset($config['clear_all_spi_cache_on_symfony_clear_cache'])) { + $container->setParameter( + 'ezpublish_legacy.clear_all_spi_cache_on_symfony_clear_cache', + $config['clear_all_spi_cache_on_symfony_clear_cache'] + ); + } + + if (isset($config['clear_all_spi_cache_from_legacy'])) { + $container->setParameter( + 'ezpublish_legacy.clear_all_spi_cache_from_legacy', + $config['clear_all_spi_cache_from_legacy'] + ); + } + // Templating $loader->load('templating.yml'); diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index 56bd665..36772aa 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -226,6 +226,8 @@ services: - "@ezpublish.cache_pool" - "@ezpublish.spi.persistence.cache.locationHandler" - '@Ibexa\Core\Persistence\Cache\Tag\CacheIdentifierGeneratorInterface' + - '%ezpublish_legacy.clear_all_spi_cache_on_symfony_clear_cache%' + - '%ezpublish_legacy.clear_all_spi_cache_from_legacy%' tags: - { name: kernel.cache_clearer } lazy: true