fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / zendframework / zend-cache / doc / book / pattern / callback-cache.md
blob54ff4ad7c5e449a27422eb2c31bee90262824bfd
1 # CallbackCache
4 The callback cache pattern caches the results of arbitrary PHP callables.
6 ## Quick Start
8 ```php
9 use Zend\Cache\PatternFactory;
10 use Zend\Cache\Pattern\PatternOptions;
12 // Via the factory:
13 $callbackCache = PatternFactory::factory('callback', [
14     'storage'      => 'apc',
15     'cache_output' => true,
16 ]);
18 // Or the equivalent manual instantiation:
19 $callbackCache = new \Zend\Cache\Pattern\CallbackCache();
20 $callbackCache->setOptions(new PatternOptions([
21     'storage'      => 'apc',
22     'cache_output' => true,
23 ]));
24 ```
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.
33 ## Available Methods
35 In addition to the methods defined in the `PatternInterface`, this
36 implementation provides the following methods.
38 ```php
39 namespace Zend\Cache\Pattern;
41 use Zend\Cache\Exception;
42 use Zend\Stdlib\ErrorHandler;
44 class CallbackCache extends AbstractPattern
46     /**
47      * Call the specified callback or get the result from cache
48      *
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
53      * @throws \Exception
54      */
55     public function call($callback, array $args = []);
57     /**
58      * Intercept method overloading; proxies to call()
59      *
60      * @param  string $function  Function name to call
61      * @param  array  $args      Function arguments
62      * @return mixed
63      * @throws Exception\RuntimeException
64      * @throws \Exception
65      */
66     public function __call($function, array $args);
68     /**
69      * Generate a unique key in base of a key representing the callback part
70      * and a key representing the arguments part.
71      *
72      * @param  callable   $callback  A valid callback
73      * @param  array      $args      Callback arguments
74      * @return string
75      * @throws Exception\RuntimeException
76      * @throws Exception\InvalidArgumentException
77      */
78     public function generateKey($callback, array $args = []);
80 ```
82 ## Examples
84 ### Instantiating the callback cache pattern
86 ```php
87 use Zend\Cache\PatternFactory;
89 $callbackCache = PatternFactory::factory('callback', [
90     'storage' => 'apc'
91 ]);
92 ```