DesertCoderz

Enable Shopware Caching far beyond 20 seconds

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.

Share:

Facebook
LinkedIn
WhatsApp

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular

Get The Latest Updates

Subscribe To Our Weekly Newsletter

No spam, notifications only about new products, updates.

Categories

On Key

Related Posts