Shopware HTTP Cache with Redis

Shopware stores the HTTP cache on the file system by default. This behavior can lead to performance problems if the store has a high number of accesses. The Linux-based in-memory service Redis provides a remedy here.

Preparation in Shopware

First, a Redis server must be made available for the server. This can either be set up locally on the app server or externally, e.g. via an accelerator server. You can find more information about our accelerator servers here:

Configuration via the Shopware environment configuration

Create a new configuration file under the path: config/packages/framework.yaml. This configuration file can be used to configure the HTTP cache. Then add the following content to the file:

        default_redis_provider: 'redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%'
                adapter: cache.adapter.redis_tag_aware
                provider: 'redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%/%env(REDIS_DB_HTTP_CACHE)%'
                tags: cache.tags

The following environment variables are used in this configuration file:

Variable Description
REDIS_HOST Host name or IP address for the Redis server
REDIS_PORT 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 the Shopware environment configuration .env.local. To do this, open the .env.local file in the Shopware root directory and add the following part to the existing configuration:

# .env.local

# [...]

# HTTP Cache Configuration

Then save the file and empty the Shopware cache via the console:

bin/console cache:clear

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

Shopware provides further information and adapters in the official documentation.

To the Shopware documentation →