Skip to content

Cache

There are several caches in Shopware that can be used to optimize performance. This page gives a brief overview and shows how to configure them.

Overview

The HTTP Cache is a must-have for every production system. With an enabled cache, the performance of the shop can be greatly increased.

How to configure the HTTP cache

The HTTP cache configuration takes place completely in the .env file. The following configurations are available here:

NameDescription
SHOPWARE_HTTP_CACHE_ENABLEDEnables the HTTP cache
SHOPWARE_HTTP_DEFAULT_TTLDefines the default cache time

How to change the cache storage

The standard Shopware HTTP cache can be exchanged or reconfigured in several ways. The standard cache comes with an adapter.filesystem. The configuration can be found in the shopware/src/Core/Framework/Resources/config/packages/framework.yaml file.

yaml
framework:
    cache:
        pools:
            cache.http:
                adapter: cache.adapter.filesystem

This is a Symfony cache pool configuration and therefore supports all adapters from the Symfony FrameworkBundle.

App cache

The app cache defines the default cache adapter for Shopware. As you can see in this default configuration, every cache-pool in Shopware uses the adapter defined in the app cache as default:

yaml
framework:
    cache:
        prefix_seed: "%kernel.cache.hash%"
        app: cache.adapter.filesystem
        pools:
            cache.object:
                default_lifetime: 3600
                adapter: cache.app
                tags: cache.tags
            cache.http:
                default_lifetime: 3600
                adapter: cache.app
                tags: cache.tags
            cache.tags:
                adapter: cache.app

This is also a Symfony cache configuration and supports all adapters from the Symfony FrameworkBundle.

Object Cache

The object cache pool is used for caching the data abstraction layer in Shopware and can be configured like any other pool.

Example: replace some cache with Redis

"Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker." In this example, we change the default HTTP cache adapter to Redis. It is possible to change every adapter as in this example. A running Redis instance is required for this to work. The configuration can be overridden by creating or editing the file framework.yaml

For cache.adapter.redis_tag_aware minimum Shopware 6.5.8.3 is required. Otherwise use cache.adapter.redis.

yaml
# config/packages/framework.yaml
framework:
    cache:
        default_redis_provider: 'redis://host:port'
        pools:
            cache.http:
                adapter: cache.adapter.redis_tag_aware
                tags: cache.tags

Replace the host and port with your Redis instance. It is also possible to change the cache adapter for app, which would affect every pool since they inherit from app by default.

yaml
framework:
    cache:
        app: cache.adapter.redis_tag_aware
        default_redis_provider: 'redis://host:port'

Redis configuration

As the cached information is ephemeral and can be recreated, it is not necessary to configure Redis to store the data on disk. For maximum performance you can configure Redis to use no persistence, refer to the Redis docs for details.

As key eviction policy you should use volatile-lru, which only automatically deletes data that is expired, as the application explicitly manages the TTL for each cache item. For a detailed overview of Redis key eviction policies see the Redis docs.