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 callback cache pattern caches the results of arbitrary PHP callables.
use Zend\Cache\PatternFactory;
use Zend\Cache\Pattern\PatternOptions;
// Via the factory:
$callbackCache = PatternFactory::factory('callback', [
'storage' => 'apc',
'cache_output' => true,
]);
// Or the equivalent manual instantiation:
$callbackCache = new \Zend\Cache\Pattern\CallbackCache();
$callbackCache->setOptions(new PatternOptions([
'storage' => 'apc',
'cache_output' => true,
]));
| Option | Data Type | Default Value | Description |
|---|---|---|---|
storage |
`string | array | Zend\Cache\Storage\StorageInterface` |
cache_output |
boolean |
true |
Whether or not to cache callback output. |
In addition to the methods defined in the PatternInterface, this
implementation provides the following methods.
namespace Zend\Cache\Pattern;
use Zend\Cache\Exception;
use Zend\Stdlib\ErrorHandler;
class CallbackCache extends AbstractPattern
{
/**
* Call the specified callback or get the result from cache
*
* [@param](https://github.com/param) callable $callback A valid callback
* [@param](https://github.com/param) array $args Callback arguments
* [@return](https://github.com/return) mixed Result
* [@throws](https://github.com/throws) Exception\RuntimeException if invalid cached data
* [@throws](https://github.com/throws) \Exception
*/
public function call($callback, array $args = []);
/**
* Intercept method overloading; proxies to call()
*
* [@param](https://github.com/param) string $function Function name to call
* [@param](https://github.com/param) array $args Function arguments
* [@return](https://github.com/return) mixed
* [@throws](https://github.com/throws) Exception\RuntimeException
* [@throws](https://github.com/throws) \Exception
*/
public function __call($function, 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) callable $callback A valid callback
* [@param](https://github.com/param) array $args Callback arguments
* [@return](https://github.com/return) string
* [@throws](https://github.com/throws) Exception\RuntimeException
* [@throws](https://github.com/throws) Exception\InvalidArgumentException
*/
public function generateKey($callback, array $args = []);
}
use Zend\Cache\PatternFactory;
$callbackCache = PatternFactory::factory('callback', [
'storage' => 'apc'
]);
How can I help you explore Laravel packages today?