Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version
WARNING: You are browsing the documentation for Symfony 3.3 which is not maintained anymore. Consider upgrading your projects to Symfony 5.1.

Proxy Cache Adapter

3.3 version

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:

use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ProxyAdapter;

$psr6CachePool = \\ create your own cache pool instance that implements the PSR-6
                 \\ interface `CacheItemPoolInterface`

$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.