Zend\Cache\Pattern

Overview

Cache patterns are configurable objects to solve known performance bottlenecks. Each should be used only in the specific situations they are designed to address. For example you can use one of the CallbackCache, ObjectCache or ClassCache patterns to cache method and function calls; to cache output generation, the OutputCache pattern could assist.

All cache patterns implement the same interface, Zend\Cache\Pattern\PatternInterface, and most extend the abstract class Zend\Cache\Pattern\AbstractPattern to implement basic logic.

Configuration is provided via the Zend\Cache\Pattern\PatternOptions class, which can simply be instantiated with an associative array of options passed to the constructor. To configure a pattern object, you can set an instance of Zend\Cache\Pattern\PatternOptions with setOptions, or provide your options (either as an associative array or PatternOptions instance) as the second argument to the factory.

It’s also possible to use a single instance of Zend\Cache\Pattern\PatternOptions and pass it to multiple pattern objects.

Quick Start

Pattern objects can either be created from the provided Zend\Cache\PatternFactory factory, or, by simply instantiating one of the Zend\Cache\Pattern\*Cache classes.

1
2
3
4
// Via the factory:
$callbackCache = Zend\Cache\PatternFactory::factory('callback', array(
    'storage' => 'apc',
));
1
2
3
4
5
// OR, the equivalent manual instantiation:
$callbackCache = new Zend\Cache\Pattern\CallbackCache();
$callbackCache->setOptions(new Zend\Cache\Pattern\PatternOptions(array(
    'storage' => 'apc',
)));

Available Methods

The following methods are implemented by Zend\Cache\Pattern\AbstractPattern. Please read documentation of specific patterns to get more information.

setOptions(Zend\Cache\Pattern\PatternOptions $options)

Set pattern options.

Return type:Zend\Cache\Pattern\PatternInterface
getOptions()

Get all pattern options.

Return type:Zend\Cache\Pattern\PatternOptions

Table Of Contents

Previous topic

Zend\Cache\Storage\Plugin

Next topic

Zend\Cache\Pattern\CallbackCache

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

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. Login with your GitHub account.
  2. Go to Zend\Cache\Pattern on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. 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.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.