Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Cache Laravel Package

zendframework/zend-cache

zendframework/zend-cache provides flexible caching for PHP apps with multiple storage backends (filesystem, memory, APCu, Redis, and more). Supports cache patterns, plugins, serialization, and configurable adapters to improve performance and reduce repeated work.

View on GitHub
Deep Wiki
Context7

ObjectCache

The ObjectCache pattern is an extension to the CallbackCache pattern. It has the same methods, but instead caches output from any instance method calls or public properties.

Quick Start

use stdClass;
use Zend\Cache\PatternFactory;

$object      = new stdClass();
$objectCache = PatternFactory::factory('object', [
    'object'  => $object,
    'storage' => 'apc'
]);

Configuration Options

Option Data Type Default Value Description
storage `string array Zend\Cache\Storage\StorageInterface`
object object none The object for which to cache method calls.
object_key `null string` Class name of object
cache_output boolean true Whether or not to cache method output.
cache_by_default boolean true Cache all 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 blacklist (if cache_by_default is enabled).
object_cache_magic_properties boolean false Whether or not to cache properties exposed by method overloading.

Available Methods

In addition to the methods defined in PatternInterface, this implementation defines the following methods.

namespace Zend\Cache\Pattern;

use Zend\Cache\Exception;

class ObjectCache extends CallbackCache
{
    /**
     * Call and cache a class method
     *
     * [@param](https://github.com/param)  string $method  Method name to call
     * [@param](https://github.com/param)  array  $args    Method arguments
     * [@return](https://github.com/return) mixed
     * [@throws](https://github.com/throws) Exception\RuntimeException
     * [@throws](https://github.com/throws) \Exception
     */
    public function call($method, array $args = []);

    /**
     * Method overloading: proxies to call().
     *
     * [@param](https://github.com/param)  string $method  Method name to call
     * [@param](https://github.com/param)  array  $args    Method arguments
     * [@return](https://github.com/return) mixed
     * [@throws](https://github.com/throws) Exception\RuntimeException
     * [@throws](https://github.com/throws) \Exception
     */
    public function __call($method, array $args);

    /**
     * Generate a unique key in base of a key representing the callback part
     * and a key representing the arguments part.
     *
     * [@param](https://github.com/param)  string     $method  The method
     * [@param](https://github.com/param)  array      $args    Callback arguments
     * [@return](https://github.com/return) string
     * [@throws](https://github.com/throws) Exception\RuntimeException
     */
    public function generateKey($method, array $args = []);

    /**
     * Property overloading: write data to a named property.
     *
     * NOTE:
     * Magic properties will be cached too if the option cacheMagicProperties
     * is enabled and the property doesn't exist in real. If so it calls __set
     * and removes cached data of previous __get and __isset calls.
     *
     * [@param](https://github.com/param)  string $name
     * [@param](https://github.com/param)  mixed  $value
     * [@return](https://github.com/return) void
     * [@see](https://github.com/see)    http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
     */
    public function __set($name, $value);

    /**
     * Property overloading: read data from a named property.
     *
     * NOTE:
     * Magic properties will be cached too if the option cacheMagicProperties
     * is enabled and the property doesn't exist in real. If so it calls __get.
     *
     * [@param](https://github.com/param)  string $name
     * [@return](https://github.com/return) mixed
     * [@see](https://github.com/see) http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
     */
    public function __get($name);

    /**
     * Property overloading: check if a named property exists.
     *
     * NOTE:
     * Magic properties will be cached too if the option cacheMagicProperties
     * is enabled and the property doesn't exist in real. If so it calls __get.
     *
     * [@param](https://github.com/param)  string $name
     * [@return](https://github.com/return) bool
     * [@see](https://github.com/see)    http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
     */
    public function __isset($name);

    /**
     * Property overloading: unset a named property.
     *
     * NOTE:
     * Magic properties will be cached too if the option cacheMagicProperties
     * is enabled and the property doesn't exist in real. If so it removes
     * previous cached __isset and __get calls.
     *
     * [@param](https://github.com/param)  string $name
     * [@return](https://github.com/return) void
     * [@see](https://github.com/see)    http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
     */
    public function __unset($name);

    /**
     * Handle casting to string
     *
     * [@return](https://github.com/return) string
     * [@see](https://github.com/see)    http://php.net/manual/language.oop5.magic.php#language.oop5.magic.tostring
     */
    public function __toString();

    /**
     * Intercept and cache invokable usage.
     *
     * [@return](https://github.com/return) mixed
     * [@see](https://github.com/see)    http://php.net/manual/language.oop5.magic.php#language.oop5.magic.invoke
     */
    public function __invoke();
}

Examples

Caching a Filter

$filter       = new Zend\Filter\RealPath();
$cachedFilter = Zend\Cache\PatternFactory::factory('object', [
    '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", ['/www/var/path/../../mypath']);

// OR
$path = $cachedFilter->filter('/www/var/path/../../mypath');
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport