Proxy Cache Adapter

Proxy Cache Adapter

This adapter wraps a PSR-6 compliant cache item pool interface. It is used to integrate your application’s cache item pool implementation with the Symfony Cache Component by consuming any implementation of Psr\Cache\CacheItemPoolInterface.

It can also be used to prefix all keys automatically before storing items in the decorated pool, effectively allowing the creation of several namespaced pools out of a single one.

This adapter expects a Psr\Cache\CacheItemPoolInterface instance as its first parameter, and optionally a namespace and default cache lifetime as its second and third parameters:

  1. use Psr\Cache\CacheItemPoolInterface;
  2. use Symfony\Component\Cache\Adapter\ProxyAdapter;
  3. // create your own cache pool instance that implements
  4. // the PSR-6 CacheItemPoolInterface
  5. $psr6CachePool = ...
  6. $cache = new ProxyAdapter(
  7. // a cache pool instance
  8. CacheItemPoolInterface $psr6CachePool,
  9. // a string prefixed to the keys of the items stored in this cache
  10. $namespace = '',
  11. // the default lifetime (in seconds) for cache items that do not define their
  12. // own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
  13. // until the cache is cleared)
  14. $defaultLifetime = 0
  15. );

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.