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
You have a running Redis server which is accessible from the PHP application.
For more information, see How to Deploy and Run Redis in a Docker Container.
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",
);
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%'
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.