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.
The ClassCache pattern is an extension to the
CallbackCache pattern. It has the same methods, but
instead generates the callbacks for any public static method invoked on the
class being cached, and caches static properties.
use Zend\Cache\PatternFactory;
$classCache = PatternFactory::factory('class', [
'class' => 'MyClass',
'storage' => 'apc',
]);
| Option | Data Type | Default Value | Description |
|---|---|---|---|
storage |
`string | array | Zend\Cache\Storage\StorageInterface` |
class |
string |
none | Name of the class for which to cache method output. |
cache_output |
boolean |
true |
Whether or not to cache method output. |
cache_by_default |
boolean |
true |
Cache all 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 omit from caching (if cache_by_default is enabled). |
In addition to the methods defined in PatternInterface, this implementation
exposes the following methods.
namespace Zend\Cache\Pattern;
use Zend\Cache;
use Zend\Cache\Exception;
class ClassCache 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 = []);
/**
* Intercept 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)
{
return $this->call($method, $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: set a static property.
*
* [@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)
{
$class = $this->getOptions()->getClass();
$class::$name = $value;
}
/**
* Property overloading: get a static property.
*
* [@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)
{
$class = $this->getOptions()->getClass();
return $class::$name;
}
/**
* Property overloading: does the named static property exist?
*
* [@param](https://github.com/param) string $name
* [@return](https://github.com/return) bool
*/
public function __isset($name)
{
$class = $this->getOptions()->getClass();
return isset($class::$name);
}
/**
* Property overloading: unset a static property.
*
* [@param](https://github.com/param) string $name
* [@return](https://github.com/return) void
*/
public function __unset($name)
{
$class = $this->getOptions()->getClass();
unset($class::$name);
}
}
$cachedFeedReader = Zend\Cache\PatternFactory::factory('class', [
'class' => 'Zend\Feed\Reader\Reader',
'storage' => 'apc',
// The feed reader doesn't output anything,
// so the output doesn'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/');
How can I help you explore Laravel packages today?