Previous Next



Cache storage plugins are objects to add missing functionality or to influence behavior of a storage adapter.

The plugins listen to events the adapter triggers and can change called method arguments (*.post - events), skipping and directly return a result (using stopPropagation), changing the result (with setResult of Zend\Cache\Storage\PostEvent) and catching exceptions (with Zend\Cache\Storage\ExceptionEvent).

Quick Start

Storage plugins can either be created from Zend\Cache\StorageFactory with the pluginFactory, or by simply instantiating one of the Zend\Cache\Storage\Plugin\*classes.

To make life easier, the Zend\Cache\StorageFactory comes with the method factory to create an adapter and all given plugins at once.

use Zend\Cache\StorageFactory;

// Via factory:
$cache = StorageFactory::factory(array(
    'adapter' => 'filesystem',
    'plugins' => array('serializer'),

// Alternately:
$cache  = StorageFactory::adapterFactory('filesystem');
$plugin = StorageFactory::pluginFactory('serializer');

// Or manually:
$cache  = new Zend\Cache\Storage\Adapter\Filesystem();
$plugin = new Zend\Cache\Storage\Plugin\Serializer();

Configuration Options


Set the automatic clearing factor. Used by the ClearByFactor plugin.

  • setClearingFactor ( int $clearingFactor )

    Implements a fluent interface.

  • getClearingFactor ( void )

    Returns int


Flag indicating whether or not to clear by namespace. Used by the ClearByFactor plugin.

  • setClearByNamespace ( bool $clearByNamespace )

    Implements a fluent interface.

  • getClearByNamespace ( void )

    Returns bool


Set callback to call on intercepted exception. Used by the ExceptionHandler plugin.

  • setExceptionCallback ( callable $exceptionCallback )

    Implements a fluent interface.

  • getExceptionCallback ( void )

    Returns null|callable


Set automatic optimizing factor. Used by the OptimizeByFactor plugin.

  • setOptimizingFactor ( int $optimizingFactor )

    Implements a fluent interface.

  • getOptimizingFactor ( void )

    Returns int


Set serializer adapter to use. Used by Serializer plugin.

  • setSerializer ( string|Zend\Serializer\Adapter $serializer )

    Implements a fluent interface.

  • getSerializer ( void )

    Returns Zend\Serializer\Adapter


Set configuration options for instantiating a serializer adapter. Used by the Serializer plugin.

  • setSerializerOptions ( array $serializerOptions )

    Implements a fluent interface.

  • getSerializerOptions ( void )

    Returns array


Set flag indicating we should re-throw exceptions. Used by the ExceptionHandler plugin.

  • setThrowExceptions ( bool $throwExceptions )

    Implements a fluent interface.

  • getThrowExceptions ( void )

    Returns bool

Available Methods

setOptions ( Zend\Cache\Storage\Plugin\PluginOptions $options )

Set options

Implements a fluent interface.

getOptions ( void )

Get options

Returns PluginOptions

attach ( EventCollection $events )

Defined by Zend\EventManager\ListenerAggregate, attach one or more listeners.

Returns void

detach ( EventCollection $events )

Defined by Zend\EventManager\ListenerAggregate, detach all previously attached listeners.

Returns void

TODO: Examples

Previous Next