The ClassCache pattern is an extension to the CallbackCache pattern. It has the same methods but instead it generates the internally used callback in base of the configured class name and the given method name.
Instantiating the class cache pattern
1 2 3 4 5 6 | use Zend\Cache\PatternFactory;
$classCache = PatternFactory::factory('class', array(
'class' => 'MyClass',
'storage' => 'apc'
));
|
Option | Data Type | Default Value | Description |
---|---|---|---|
storage | string array Zend\Cache\Storage\StorageInterface | <none> | The storage to write/read cached data |
class | string | <none> | The class name |
cache_output | boolean | true | Cache output of callback |
cache_by_default | boolean | true | Cache method calls by default |
class_cache_methods | array | [] | List of methods to cache (If cache_by_default is disabled) |
class_non_cache_methods | array | [] | List of methods to no-cache (If cache_by_default is enabled) |
call(string $method, array $args = array())
Call the specified method of the configured class
Returns the result
__call(string $method, array $args)
Call the specified method of the configured class
Returns the result
__set
__set(string $name, mixed $value)
Set a static property of the configured class
__get
__get(string $name)
Get a static property of the configured class
__isset
__isset(string $name)
Checks if a static property of the configured class exists
__unset
__unset(string $name)
Unset a static property of the configured class
generateKey(string $method, array $args = array())
Generate a unique key in base of a key representing the callback part and a key representing the arguments part.
Returns the key
setOptions(Zend\Cache\Pattern\PatternOptions $options)
Set pattern options
Returns Zend\Cache\Pattern\ClassCache
getOptions()
Get all pattern options
Returns PatternOptions instance.
Caching of import feeds
1 2 3 4 5 6 7 8 9 10 11 12 | $cachedFeedReader = Zend\Cache\PatternFactory::factory('class', array(
'class' => 'Zend\Feed\Reader\Reader',
'storage' => 'apc',
// The feed reader doesn't output anything
// so the output don't need to be catched and cached
'cache_output' => false,
));
$feed = $cachedFeedReader->call("import", array('http://www.planet-php.net/rdf/'));
// OR
$feed = $cachedFeedReader->import('http://www.planet-php.net/rdf/');
|
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.