Switching to Redis

Replace the default cache implementation with Redis by implementing the CacheItemPoolFactoryInterface to create a Symfony redis adapter.

For an illustration, check our demo component.

Prerequisites

Procedure

1. Implementation of CacheItemPoolFactoryInterface and using Symfony redis adapter. The key point here is to configure the namespace parameter.

return new RedisAdapter(
    RedisAdapter::createConnection($this->dsn),
    namespace: "cache_items_shop_$shopId",
);
  1. In the service YAML file, define the service. In the cache.redis.dsn parameter, use your own Redis server’s DNS.

cache.redis.dsn: 'redis://localhost:6379'

OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CacheItemPoolFactoryInterface:
    class: OxidEsales\ComponentTemplate\Cache\RedisCacheItemPoolFactory
    arguments:
        $dsn: '%cache.redis.dsn%'
  1. In the root service YAML file of the component, import the new factory service:

imports:
    - { resource: src/Cache/services.yaml }

Result

After the installation of the component, the default filesystem caching is replaced with the new Redis-based caching.