fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / zendframework / zend-cache / doc / book / pattern / class-cache.md
blob6d87b948f11eb1f2855e99125db70d0349e1a0bd
1 # ClassCache
3 The `ClassCache` pattern is an extension to the
4 [`CallbackCache`](callback-cache.md) pattern. It has the same methods, but
5 instead generates the callbacks for any public static method invoked on the
6 class being cached, and caches static properties.
8 ## Quick Start
10 ```php
11 use Zend\Cache\PatternFactory;
13 $classCache = PatternFactory::factory('class', [
14     'class'   => 'MyClass',
15     'storage' => 'apc',
16 ]);
17 ```
19 ## Configuration Options
21 Option | Data Type | Default Value | Description
22 ------ | --------- | ------------- | -----------
23 `storage` | `string | array | Zend\Cache\Storage\StorageInterface` | none | Adapter used for reading and writing cached data.
24 `class` | `string` | none | Name of the class for which to cache method output.
25 `cache_output` | `boolean` | `true` | Whether or not to cache method output.
26 `cache_by_default` | `boolean` | `true` | Cache all method calls by default.
27 `class_cache_methods` | `array` | `[]` | List of methods to cache (if `cache_by_default` is disabled).
28 `class_non_cache_methods` | `array` | `[]` | List of methods to omit from caching (if `cache_by_default` is enabled).
30 ## Available Methods
32 In addition to the methods defined in `PatternInterface`, this implementation
33 exposes the following methods.
35 ```php
36 namespace Zend\Cache\Pattern;
38 use Zend\Cache;
39 use Zend\Cache\Exception;
41 class ClassCache extends CallbackCache
43     /**
44      * Call and cache a class method
45      *
46      * @param  string $method  Method name to call
47      * @param  array  $args    Method arguments
48      * @return mixed
49      * @throws Exception\RuntimeException
50      * @throws \Exception
51      */
52     public function call($method, array $args = []);
54     /**
55      * Intercept method overloading; proxies to call().
56      *
57      * @param  string $method  Method name to call
58      * @param  array  $args    Method arguments
59      * @return mixed
60      * @throws Exception\RuntimeException
61      * @throws \Exception
62      */
63     public function __call($method, array $args)
64     {
65         return $this->call($method, $args);
66     }
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  string     $method  The method
73      * @param  array      $args    Callback arguments
74      * @return string
75      * @throws Exception\RuntimeException
76      */
77     public function generateKey($method, array $args = []);
79     /**
80      * Property overloading: set a static property.
81      *
82      * @param  string $name
83      * @param  mixed  $value
84      * @return void
85      * @see   http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
86      */
87     public function __set($name, $value)
88     {
89         $class = $this->getOptions()->getClass();
90         $class::$name = $value;
91     }
93     /**
94      * Property overloading: get a static property.
95      *
96      * @param  string $name
97      * @return mixed
98      * @see    http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
99      */
100     public function __get($name)
101     {
102         $class = $this->getOptions()->getClass();
103         return $class::$name;
104     }
106     /**
107      * Property overloading: does the named static property exist?
108      *
109      * @param  string $name
110      * @return bool
111      */
112     public function __isset($name)
113     {
114         $class = $this->getOptions()->getClass();
115         return isset($class::$name);
116     }
118     /**
119      * Property overloading: unset a static property.
120      *
121      * @param  string $name
122      * @return void
123      */
124     public function __unset($name)
125     {
126         $class = $this->getOptions()->getClass();
127         unset($class::$name);
128     }
132 ## Examples
134 **Caching of import feeds**
136 ```php
137 $cachedFeedReader = Zend\Cache\PatternFactory::factory('class', [
138     'class'   => 'Zend\Feed\Reader\Reader',
139     'storage' => 'apc',
141     // The feed reader doesn't output anything,
142     // so the output doesn't need to be caught and cached:
143     'cache_output' => false,
146 $feed = $cachedFeedReader->call("import", array('http://www.planet-php.net/rdf/'));
148 // OR
149 $feed = $cachedFeedReader->import('http://www.planet-php.net/rdf/');