Shopware app cache with Redis
The app cache defines the standard cache adapter for Shopware. Shopware stores the app cache on the file system. If the store has a high number of accesses, this behavior can lead to performance problems. The Linux-based in-memory service Redis provides a remedy here.
The following describes how to configure Redis as a cache adapter for all Shopware caches.
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: https://www.creoline.com/de/products/redis-server
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 app cache. Then add the following content to the file:
framework:
cache:
app: cache.adapter.redis_tag_aware
default_redis_provider: 'redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%/%env(REDIS_DB_APP_CACHE)%'
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_APP_CACHE | Redis database for the app 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
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB_APP_CACHE=1
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 app cache.
Further links
Shopware provides further information and adapters in the official documentation.