Zend\Cache\Pattern\CallbackCache

Overview

The callback cache pattern caches calls of non specific functions and methods given as a callback.

Quick Start

For instantiation you can use the PatternFactory or do it manual:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
use Zend\Cache\PatternFactory;
use Zend\Cache\Pattern\PatternOptions;

// Via the factory:
$callbackCache = PatternFactory::factory('callback', array(
    'storage'      => 'apc',
    'cache_output' => true,
));

// OR, the equivalent manual instantiation:
$callbackCache = new \Zend\Cache\Pattern\CallbackCache();
$callbackCache->setOptions(new PatternOptions(array(
    'storage'      => 'apc',
    'cache_output' => true,
)));

Configuration Options

Option Data Type Default Value Description
storage string array Zend\Cache\Storage\StorageInterface <none> The storage to write/read cached data
cache_output boolean true Cache output of callback

Available Methods

call(callable $callback, array $args = array())

Call the specified callback or get the result from cache.

Return type:mixed
__call(string $function, array $args)

Function call handler.

Return type:mixed
generateKey(callable $callback, array $args = array())

Generate a unique key in base of a key representing the callback part and a key representing the arguments part.

Return type:string
setOptions(Zend\Cache\Pattern\PatternOptions $options)

Set pattern options.

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

Get all pattern options.

Return type:Zend\Cache\Pattern\PatternOptions

Examples

Instantiating the callback cache pattern

1
2
3
4
5
use Zend\Cache\PatternFactory;

$callbackCache = PatternFactory::factory('callback', array(
    'storage' => 'apc'
));

Table Of Contents

Previous topic

Zend\Cache\Pattern

Next topic

Zend\Cache\Pattern\ClassCache

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\CallbackCache 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.