Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

3.1.2 2021-11-18 16:54 UTC


Build Status

Laminas\Cache provides a general cache system for PHP. The Laminas\Cache component is able to cache different patterns (class, object, output, etc) using different storage adapters (DB, File, Memcache, etc).


If this component is used without laminas-mvc or mezzio, a PSR-11 container to fetch services, adapters, plugins, etc. is needed.

The easiest way would be to use laminas-config-aggregator along with laminas-servicemanager.

use Laminas\Cache\ConfigProvider;
use Laminas\Cache\Service\StorageAdapterFactoryInterface;
use Laminas\Cache\Storage\Adapter\Memory;
use Laminas\ConfigAggregator\ConfigAggregator;
use Laminas\ServiceManager\ServiceManager;

$config = (new ConfigAggregator([

$dependencies = $config['dependencies'];

$container = new ServiceManager($dependencies);

/** @var StorageAdapterFactoryInterface $storageFactory */
$storageFactory = $container->get(StorageAdapterFactoryInterface::class);

$storage = $storageFactory->create(Memory::class);

$storage->setItem('foo', 'bar');


We provide scripts for benchmarking laminas-cache using the PHPBench framework; these can be found in the benchmark/ directory.

To execute the benchmarks you can run the following command:

$ vendor/bin/phpbench run --report=aggregate