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.
11 use Zend\Cache\PatternFactory;
13 $classCache = PatternFactory::factory('class', [
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).
32 In addition to the methods defined in `PatternInterface`, this implementation
33 exposes the following methods.
36 namespace Zend\Cache\Pattern;
39 use Zend\Cache\Exception;
41 class ClassCache extends CallbackCache
44 * Call and cache a class method
46 * @param string $method Method name to call
47 * @param array $args Method arguments
49 * @throws Exception\RuntimeException
52 public function call($method, array $args = []);
55 * Intercept method overloading; proxies to call().
57 * @param string $method Method name to call
58 * @param array $args Method arguments
60 * @throws Exception\RuntimeException
63 public function __call($method, array $args)
65 return $this->call($method, $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 string $method The method
73 * @param array $args Callback arguments
75 * @throws Exception\RuntimeException
77 public function generateKey($method, array $args = []);
80 * Property overloading: set a static property.
85 * @see http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
87 public function __set($name, $value)
89 $class = $this->getOptions()->getClass();
90 $class::$name = $value;
94 * Property overloading: get a static property.
98 * @see http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
100 public function __get($name)
102 $class = $this->getOptions()->getClass();
103 return $class::$name;
107 * Property overloading: does the named static property exist?
109 * @param string $name
112 public function __isset($name)
114 $class = $this->getOptions()->getClass();
115 return isset($class::$name);
119 * Property overloading: unset a static property.
121 * @param string $name
124 public function __unset($name)
126 $class = $this->getOptions()->getClass();
127 unset($class::$name);
134 **Caching of import feeds**
137 $cachedFeedReader = Zend\Cache\PatternFactory::factory('class', [
138 'class' => 'Zend\Feed\Reader\Reader',
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/'));
149 $feed = $cachedFeedReader->import('http://www.planet-php.net/rdf/');