PHP simple static cache class
Via Composer
$ composer require gregoriohc/static-cacheif (Cache::has('key')) {
// ...
}Cache::set('key', 'value');$value = Cache::get('key');If you wish, you may pass a second argument to the get method specifying the default value you wish to be returned if the item doesn't exist:
$value = Cache::get('key', 'default');You may even pass a Closure as the default value. The result of the Closure will be returned if the specified item does not exist in the cache:
Cache::get('key', function() {
return 'value';
});Sometimes you may wish to retrieve an item from the cache, but also store a default value if the requested item doesn't exist. You may do this using the remember method:
Cache::remember('key', function() {
return 'value';
});If the item does not exist in the cache, the Closure passed to the remember method will be executed and its result will be placed in the cache.
Cache::forget('key');$ composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker.
You're free to use this package, but if it makes it to your production environment I highly appreciate you sharing it on any social network.
The MIT License (MIT). Please see License File for more information.