The callback cache pattern caches calls of non specific functions and methods given as a callback.
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,
)));
|
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 |
call(callable $callback, array $args = array())
Call the specified callback or get the result from cache
Returns the result
__call(string $function, array $args)
Function call handler
Returns the result
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.
Returns the key
setOptions(Zend\Cache\Pattern\PatternOptions $options)
Set pattern options
Returns Zend\Cache\Pattern\CallbackCache
getOptions()
Get all pattern options
Returns PatternOptions instance.
Instantiating the callback cache pattern
1 2 3 4 5 | use Zend\Cache\PatternFactory;
$callbackCache = PatternFactory::factory('callback', array(
'storage' => 'apc'
));
|
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.