laminas/laminas-cache
Laminas Cache provides flexible caching for PHP applications, with adapters for common backends, cache storage, patterns, plugins, and PSR-compatible integrations. Includes tools for configuring, managing, and testing cache behavior in Laminas apps.
The callback cache pattern caches the results of arbitrary PHP callables.
use Laminas\Cache\Pattern\CallbackCache;
use Laminas\Cache\Pattern\PatternOptions;
// Or the equivalent manual instantiation:
$callbackCache = new CallbackCache(
$storage,
new PatternOptions([
'cache_output' => true,
])
);
Storage Adapter
The
$storageadapter can be any adapter which implements theStorageInterface. Check out the Pattern Quick Start-Section for a standard adapter which can be used here.
| Option | Data Type | Default Value | Description |
|---|---|---|---|
storage |
string|array|Laminas\Cache\Storage\StorageInterface |
none | deprecated Adapter used for reading and writing cached data. |
cache_output |
bool |
true |
Whether or not to cache callback output. |
use Laminas\Cache\Pattern\CallbackCache;
$callbackCache = new CallbackCache($storage);
In addition to the methods defined in the PatternInterface and the StorageCapableInterface, this
implementation provides the following methods.
namespace Laminas\Cache\Pattern;
use Laminas\Cache\Exception;
class CallbackCache extends AbstractStorageCapablePattern
{
/**
* 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 = []);
}
How can I help you explore Laravel packages today?