Zend\Cache\Pattern\ObjectCache

Overview

The ObjectCache 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 object and the given method name.

Quick Start

Instantiating the object cache pattern

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

$object      = new stdClass();
$objectCache = PatternFactory::factory('object', array(
    'object'  => $object,
    '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
object object <none> The object to cache methods calls of
object_key null string <Class name of object> A hopefully unique key of the object
cache_output boolean true Cache output of callback
cache_by_default boolean true Cache method calls by default
object_cache_methods array [] List of methods to cache (If cache_by_default is disabled)
object_non_cache_methods array [] List of methods to no-cache (If cache_by_default is enabled)
object_cache_magic_properties boolean false Cache calls of magic object properties

Available Methods

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

Get all pattern options.

Return type:Zend\Cache\Pattern\PatternOptions

Examples

Caching a filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$filter       = new Zend\Filter\RealPath();
$cachedFilter = Zend\Cache\PatternFactory::factory('object', array(
    'object'     => $filter,
    'object_key' => 'RealpathFilter',
    'storage'    => 'apc',

    // The realpath filter doesn't output anything
    // so the output don't need to be caught and cached
    'cache_output' => false,
));

$path = $cachedFilter->call("filter", array('/www/var/path/../../mypath'));
// OR
$path = $cachedFilter->filter('/www/var/path/../../mypath');

Table Of Contents

Previous topic

Zend\Cache\Pattern\ClassCache

Next topic

Zend\Cache\Pattern\OutputCache

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

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.

  1. Login with your GitHub account.
  2. Go to Zend\Cache\Pattern\ObjectCache on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.