Zend\Cache\Pattern\ClassCache

Overview

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.

Quick Start

Instantiating the class cache pattern

1
2
3
4
5
6
use Zend\Cache\PatternFactory;

$classCache = PatternFactory::factory('class', array(
    'class'   => 'MyClass',
    'storage' => 'apc'
));

Configuration Options

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)

Available Methods

call(string $method, array $args = array())
Call the specified method of the configured class.
Return type:mixed
__call(string $method, array $args)
Call the specified method of the configured class.
Return type:mixed
__set(string $name, mixed $value)
Set a static property of the configured class.
Return type:void
__get(string $name)
Get a static property of the configured class.
Return type:mixed
__isset(string $name)
Checks if a static property of the configured class exists.
Return type:boolean
__unset(string $name)
Unset a static property of the configured class.
Return type:void
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.

Return type:string
setOptions(Zend\Cache\Pattern\PatternOptions $options)

Set pattern options.

Return type:Zend\Cache\Pattern\ClassCache
getOptions()

Get all pattern options.

Return type:Zend\Cache\Pattern\PatternOptions

Examples

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 caught 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/');