4 The callback cache pattern caches the results of arbitrary PHP callables.
9 use Zend\Cache\PatternFactory;
10 use Zend\Cache\Pattern\PatternOptions;
13 $callbackCache = PatternFactory::factory('callback', [
15 'cache_output' => true,
18 // Or the equivalent manual instantiation:
19 $callbackCache = new \Zend\Cache\Pattern\CallbackCache();
20 $callbackCache->setOptions(new PatternOptions([
22 'cache_output' => true,
26 ## Configuration Options
28 Option | Data Type | Default Value | Description
29 ------ | --------- | ------------- | -----------
30 `storage` | `string | array | Zend\Cache\Storage\StorageInterface` | none | Adapter used for reading and writing cached data.
31 `cache_output` | `boolean` | `true` | Whether or not to cache callback output.
35 In addition to the methods defined in the `PatternInterface`, this
36 implementation provides the following methods.
39 namespace Zend\Cache\Pattern;
41 use Zend\Cache\Exception;
42 use Zend\Stdlib\ErrorHandler;
44 class CallbackCache extends AbstractPattern
47 * Call the specified callback or get the result from cache
49 * @param callable $callback A valid callback
50 * @param array $args Callback arguments
51 * @return mixed Result
52 * @throws Exception\RuntimeException if invalid cached data
55 public function call($callback, array $args = []);
58 * Intercept method overloading; proxies to call()
60 * @param string $function Function name to call
61 * @param array $args Function arguments
63 * @throws Exception\RuntimeException
66 public function __call($function, array $args);
69 * Generate a unique key in base of a key representing the callback part
70 * and a key representing the arguments part.
72 * @param callable $callback A valid callback
73 * @param array $args Callback arguments
75 * @throws Exception\RuntimeException
76 * @throws Exception\InvalidArgumentException
78 public function generateKey($callback, array $args = []);
84 ### Instantiating the callback cache pattern
87 use Zend\Cache\PatternFactory;
89 $callbackCache = PatternFactory::factory('callback', [