Loads of traffic hitting your shop? Always wondered why your category pages are slow, except for the first 20 seconds? Yes, me too. So, as I suspected, that the Shopware documentation will be silent about it, I started to search intuitively in the code and found this here in:
<?php declare(strict_types=1); // vendor/shopware/core/Framework/Adapter/Cache/InvalidateCacheTask.php namespace Shopware\Core\Framework\Adapter\Cache; use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTask; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; class InvalidateCacheTask extends ScheduledTask { public static function getTaskName(): string { return 'shopware.invalidate_cache'; } public static function getDefaultInterval(): int { return 20; } public static function shouldRun(ParameterBagInterface $bag): bool { return $bag->get('shopware.cache.invalidation.delay') > 0; } }
But is there a way to change the cache invalidation value by configuration? Well, yes, kind of, in the configuration file:
config/packages/shopware.yaml
You can set the shopware.cache.invalidation.http_cache parameter or better said you can reset it.
shopware: cache: invalidation: http_cache: []
And to see it in full effect, you need to set in your .env
file the parameter: SHOPWARE_HTTP_CACHE_ENABLED=1
But let’s be said, that you need to check your requirements too. If you have different layouts for different customer groups, the caching may interfere with your requirements. After a login or a product in the cart, the context changes, and you may run into trouble due to missing cache invalidation.
So, most probably you will want to put something like this here in your config/packages/cacheconfig.yaml which you should create and discard the cache.invalidation.http_cache parameter setting mentioned above, as the default Shopware setting includes the exception to http-caching the filed-cart and logged-in user sessions.
framework: cache: app: cache.adapter.filesystem pools: cache.property_access: adapter: cache.app cache.serializer: adapter: cache.app cache.annotations: adapter: cache.app cache.property_info: adapter: cache.app cache.messenger: adapter: cache.app cache.object: default_lifetime: 86400 adapter: cache.app tags: cache.tags cache.http: default_lifetime: 86400 adapter: cache.app tags: cache.tags cache.tags: default_lifetime: 7200 adapter: cache.app shopware: cache: invalidation: delay: 0 count: 150 cart: expire_days: 21