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'
));
|