Understanding system-wide caching
Overview of the default PSR-6 caching implementation
System-wide caching uses PSR-6 cache standards.
Cache Item Pool Interface
The CacheItemPoolInterface offers functions to access, store, and remove cache items. It is utilized by all cache components throughout the system and can be accessed through the DI container.
For more information about the CacheItemPoolInterface, see PsrCacheCacheItemPoolInterface.
Implementation of Interface
Symfony FilesystemAdapter is used as default which is an adapter provided by Symfony that offers caching functionality and implements the PSR-6 standards.
For more information about the Symfony Filesystem adapter, see Filesystem Cache Adapter.
Configuration
Default configuration is defined in the corresponding services.yaml under Cache\Pool as such:
Psr\Cache\CacheItemPoolInterface:
Cache Item Pool Factory Interface
This factory contract guarantees a smooth replacement of the default implementation.
interface CacheItemPoolFactoryInterface
{
public function create(int $shopId): CacheItemPoolInterface;
}
Implementation of Factory Interface
Implementation of the interface is straightforward; the crucial aspect is to configure the namespace parameter properly to ensure caches are segregated between shops. See examples
Shop Cache Cleaner Interface
The cleaner contract provides an easy way to clear all or specific shop-related caches.
public function clear(int $shopId): void;
public function clearAll(): void;
Implementation of Cleaner Interface
ShopCacheFacade implements the interface and guarantees the invocation of the appropriate services to purge all caches. It can be used via DI
Using the Symfony Filesystem adapter
Procedure
To use the
CacheItemPoolInterfaceis straightforward via Dependency Injection (DI):
public function __construct(private readonly CacheItemPoolInterface $cache)
{
}
Note
To change the default implementation and use, for example, Redis-based caching as the default, follow the instructions in our Switching to Redis tutorial.
To clear shop caches:
public function __construct(private readonly ShopCacheCleanerInterface $cacheCleaner)
{
}
// Specific shop
$this->cacheCleaner->clear($shopId);
// All shop cache clear
$this->cacheCleaner->clearAll();
For more information, see the tutorials under Caching examples.
Area specific services
Module caching
Caching functionalities for modules
OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheInterface:
Subscribing to the module cache invalidation event
oxid_esales.module.cache.invalidate_module_cache_event_subscriber: