Shopware HTTP Cache with Redis

By default, Shopware stores the HTTP cache on the file system. If the store receives a high volume of traffic, this behavior can lead to performance issues. The Linux-based in-memory service Redis provides a solution.


Preparation in Shopware

First, a Redis server must be set up for the server. This can be configured either locally on the application server or externally, e.g., via an accelerator server. You can find more information about our accelerator servers here: https://www.creoline.com/server/redis/




Configuration via the Shopware Environment Configuration (Shopware 6.6 and later)


Starting with Shopware 6.6, the HTTP cache is stored in the app cache, which is why only this needs to be configured in this case; see Shopware App Cache with Redis.


Configuration via the Shopware Environment Configuration (up to Shopware 6.5)

Create a new configuration file at the following path: config/packages/framework.yaml. You can use this configuration file to configure the HTTP cache. Then add the following content to the file:

framework:
    cache:
 default_redis_provider: 'redis://%env(REDIS_HOST_HTTP_CACHE)%:%env(REDIS_PORT_HTTP_CACHE)%'
 pools:
 cache.http:
                adapter: cache.adapter.redis_tag_aware
 provider: 'redis://%env(REDIS_HOST_HTTP_CACHE)%:%env(REDIS_PORT_HTTP_CACHE)%/%env(REDIS_DB_HTTP_CACHE)%'
                tags: cache.tags


The following environment variables are used in this configuration file:

Variable Description
REDIS_HOST_HTTP_CACHE Hostname or IP address of the Redis server
REDIS_PORT_HTTP_CACHE TCP port for Redis connections (default: 6379)
REDIS_DB_HTTP_CACHE Redis database for the HTTP cache


The variables used here must then be added to Shopware’s .env.local environment configuration file. To do this, open the .env.local file in the Shopware root directory and add the following section to the existing configuration:

# .env.local

# [...]

# HTTP Cache Configuration
REDIS_HOST_HTTP_CACHE=127.0.0.1
REDIS_PORT_HTTP_CACHE=6379
REDIS_DB_HTTP_CACHE=2


Then save the file and clear the Shopware cache via the console using the system user or user who owns the file system:


Please use only the system user who owns the files in your Shopware installation’s file system; otherwise, the cache directory will not be created correctly, which will inevitably result in an error.


bin/console cache:clear


The Redis server is then used to manage the HTTP cache.



Shopware provides additional information and adapters in its official documentation.

Go to the Shopware documentation →