Previous Next

Zend\Cache\Storage\Plugin

Overview

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');
$cache->addPlugin($plugin);

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

Configuration Options

clearing_factor

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

  • setClearingFactor ( int $clearingFactor )

    Implements a fluent interface.

  • getClearingFactor ( void )

    Returns int

clear_by_namespace

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

exception_callback

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

  • setExceptionCallback ( callable $exceptionCallback )

    Implements a fluent interface.

  • getExceptionCallback ( void )

    Returns null|callable

optimizing_factor

Set automatic optimizing factor. Used by the OptimizeByFactor plugin.

  • setOptimizingFactor ( int $optimizingFactor )

    Implements a fluent interface.

  • getOptimizingFactor ( void )

    Returns int

serializer

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

serializer_options

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

  • setSerializerOptions ( array $serializerOptions )

    Implements a fluent interface.

  • getSerializerOptions ( void )

    Returns array

throw_exceptions

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
setOptions ( Zend\Cache\Storage\Plugin\PluginOptions $options )

Set options

Implements a fluent interface.

getOptions
getOptions ( void )

Get options

Returns PluginOptions

attach
attach ( EventCollection $events )

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

Returns void

detach
detach ( EventCollection $events )

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

Returns void

TODO: Examples

Previous Next