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.

PDO & Doctrine DBAL Cache Adapter

3.3 version

PDO & Doctrine DBAL Cache Adapter

New in version 3.2: The PDO & Doctrine DBAL adapter was introduced in Symfony 3.2.

This adapter stores the cache items in an SQL database. It requires a PDO, Doctrine DBAL Connection, or Data Source Name (DSN) as its first parameter, and optionally a namespace, default cache lifetime, and options array as its second, third, and forth parameters:

use Symfony\Component\Cache\Adapter\PdoAdapter;

$cache = new PdoAdapter(

    // a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO

    // the 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 database table is truncated or its rows are otherwise deleted)
    $defaultLifetime = 0,

    // an array of options for configuring the database connection
    $options = array()


When passed a Data Source Name (DSN) string (instead of a database connection class instance), the connection will be lazy-loaded when needed.

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