English spoken conference

Symfony 5: The Fast Track

A new book to learn about developing modern Symfony 5 applications.

Support this project

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.

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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ProxyAdapter;

// create your own cache pool instance that implements
// the PSR-6 CacheItemPoolInterface
$psr6CachePool = ...

$cache = new ProxyAdapter(

    // a cache pool instance
    CacheItemPoolInterface $psr6CachePool,

    // a string prefixed to the keys of the items stored in this cache
    $namespace = '',

    // the default lifetime (in seconds) for cache items that do not define their
    // own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
    // until the cache is cleared)
    $defaultLifetime = 0
);

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