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 4.3 which is not maintained anymore. Consider upgrading your projects to Symfony 5.1.

Array Cache Adapter

4.3 version

Array Cache Adapter

Generally, this adapter is useful for testing purposes, as its contents are stored in memory and not persisted outside the running PHP process in any way. It can also be useful while warming up caches, due to the getValues() method.

This adapter can be passed a default cache lifetime as its first parameter, and a boolean that toggles serialization as its second parameter:

use Symfony\Component\Cache\Adapter\ArrayAdapter;

$cache = new ArrayAdapter(

    // 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 current PHP process finishes)
    $defaultLifetime = 0,

    // if ``true``, the values saved in the cache are serialized before storing them
    $storeSerialized = true

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