Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Latest commit

 

History

History
145 lines (95 loc) · 5.25 KB

zend.cache.pattern.class-cache.rst

File metadata and controls

145 lines (95 loc) · 5.25 KB

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

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.

rtype

mixed

__call(string $method, array $args)

Call the specified method of the configured class.

rtype

mixed

__set(string $name, mixed $value)

Set a static property of the configured class.

rtype

void

__get(string $name)

Get a static property of the configured class.

rtype

mixed

__isset(string $name)

Checks if a static property of the configured class exists.

rtype

boolean

__unset(string $name)

Unset a static property of the configured class.

rtype

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.

rtype

string

setOptions(Zend\Cache\Pattern\PatternOptions $options)

Set pattern options.

rtype

Zend\Cache\Pattern\ClassCache

getOptions()

Get all pattern options.

rtype

Zend\Cache\Pattern\PatternOptions

Examples

Caching of import feeds

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