Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Latest commit

 

History

History
109 lines (71 loc) · 3.08 KB

zend.cache.pattern.callback-cache.rst

File metadata and controls

109 lines (71 loc) · 3.08 KB

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:

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.

rtype

mixed

__call(string $function, array $args)

Function call handler.

rtype

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.

rtype

string

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

Set pattern options.

rtype

Zend\Cache\Pattern\CallbackCache

getOptions()

Get all pattern options.

rtype

Zend\Cache\Pattern\PatternOptions

Examples

Instantiating the callback cache pattern

use Zend\Cache\PatternFactory;

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