Using the internal cache service allows you to use a interface and an interface and to not have to care about if whether the system has been configured to place the cache in Memcached or on File system. And as eZ Platform requires that instances uses use a cluster-aware cache in Cluster setup, you can safely assume your cache is shared (and invalidated) across all web servers.
Warning | ||
---|---|---|
| ||
Current implementation uses a caching library called Stash, via Stash-bundleStashBundle. We plan to move to a PSR-6 compatible cache service cable capable of supporting cache Tagging and multi get/set in the future, when that happens the interface of the cache service will change! |
Note | ||
---|---|---|
| ||
When reusing the cache service within your own code, it is very important to not conflict with the cache keys used by others, hence . That is why the example of usage below starts with a unique "myApp" key for . For the namespace of your own cache, you must do the same! So never clear cache using the cache service without your key specified, otherwise you'll clear all cache. |
...
Via Dependency injection
In your symfony Symfony services configuration you can simply define that you require the "cache" service in your configuration like so:
...
Like any other service, it is also possible to get the "cache" service via container as well like so:
Code Block | ||||
---|---|---|---|---|
| ||||
/** @var $cacheService \Tedivm\StashBundle\Service\CacheService */ $cacheService = $container->get('ezpublish.cache_pool'); |
...
Clearing Persistence cache
Persistence cache uses a separate Cache Pool decorator which by design prefixes cache keys with "ez_spi", clearing . Clearing persistence cache can thus be done in the following way:
...