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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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() 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() Returns bool
exception_callback

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

  • setExceptionCallback(callable $exceptionCallback) Implements a fluent interface.
  • getExceptionCallback() Returns null|callable
optimizing_factor

Set automatic optimizing factor. Used by the OptimizeByFactor plugin.

  • setOptimizingFactor(int $optimizingFactor) Implements a fluent interface.
  • getOptimizingFactor() Returns int
serializer

Set serializer adapter to use. Used by Serializer plugin.

  • setSerializer(string|Zend\Serializer\Adapter $serializer) Implements a fluent interface.
  • getSerializer() 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() 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() Returns bool

Available Methods

setOptions

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

Set options

Implements a fluent interface.

getOptions

getOptions()

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

Project Versions

Table Of Contents

Previous topic

Zend\Cache\Storage\Capabilities

Next topic

Zend\Cache\Pattern

This Page

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Go to Zend\Cache\Storage\Plugin on GitHub.
  2. Edit file contents using GitHub's text editor in your web browser
  3. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  4. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  5. Your changes are now queued for review under project's Pull requests tab on GitHub.