Message-ID: <818937457.3040.1485851731104.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3039_2110037355.1485851731104" ------=_Part_3039_2110037355.1485851731104 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Using the internal cache service allows you to use an inter= face and to not have to care whether the system has been configured to plac= e the cache in Memcached or on File system. And as eZ Platform requires tha= t instances use a cluster-aware cache in Cluster setup, you can safely assu= me your cache is shared (and invalidated) across all web= servers.
Interface will change in the future
Current implementation uses a caching library called Stash, = via StashBundle. We plan to move to a P= SR-6 compatible cache service capable of supporting cache Tagging and multi= get/set in the future, when that happens the interface of the cache servic= e will change!
Use unique vendor prefix for Cache key!
When reusing the cache service within your own code, it is very importan= t to not conflict with the cache keys used by others. That is why the examp= le of usage below starts with a unique "myApp" key. For the namespace of yo= ur own cache, you must do the same! So never clear cache using the cache se= rvice without your key specified, otherwise you'll clear all cache.
In your Symfony services configuration you can simply define that you re= quire the "cache" service in your configuration like so:
myApp.myService: class: %myApp.myService.class% arguments: - @ezpublish.cache_pool=20
The "cache" service is an instance of the following class: Te=
divm\StashBundle\Service\CacheService
Like any other service, it is also possible to get the "cache" service v= ia container like so:
/** @var $cacheService \Tedivm\StashBundle\Service\CacheService */ $cacheService =3D $container->get('ezpublish.cache_pool');=20
Example usage of the cache service:
$cacheItem =3D $cacheService->getItem('myApp', 'object', $id= ); $myObject =3D $cacheItem->get(); if ($cacheItem->isMiss()) { $myObject =3D $container->get('my_app.backend_service')->load= Object($id) $cacheItem->set($myObject); } return $myObject;=20
For more info on usage, take a look at Stash's documentation= .
Persistence cache uses a separate Cache Pool decorator which by design p= refixes cache keys with "ez_spi= ". Clearing persistence cache can thus be done in the following way:
/** @var $cacheService \eZ\Publish\Core\Persistence\Cache\CacheServ= iceDecorator */ $cacheService =3D $container->get('ezpublish.cache_pool.spi.cache.decora= tor'); // To clear all cache $cacheService->clear(); // To clear a specific cache item (check source code in eZ\Publish\Core\Per= sistence\Cache\*Handlers for further info) $cacheService->clear('content', 'info', $contentId); // Stash cache is hierarchical, so you can clear all content/info cache lik= e so: $cacheService->clear('content', 'info');=20