PHP Array Cache Adapter

5.3 version
Symfony 5.3 is backed by JoliCode.

PHP Array Cache AdapterΒΆ

This adapter is a high performance cache for static data (e.g. application configuration) that is optimized and preloaded into OPcache memory storage. It is suited for any data that is mostly read-only after warmup:

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;

// somehow, decide it's time to warm up the cache!
if ($needsWarmup) {
    // some static values
    $values = [
        'stats.products_count' => 4711,
        'stats.users_count' => 1356,

    $cache = new PhpArrayAdapter(
        // single file where values are cached
        __DIR__ . '/somefile.cache',
        // a backup adapter, if you set values after warmup
        new FilesystemAdapter()

// ... then, use the cache!
$cacheItem = $cache->getItem('stats.users_count');
echo $cacheItem->get();


This adapter requires turning on the opcache.enable php.ini setting.

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