static-cache
![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
PHP simple static cache class, (*2)
Install
Via Composer, (*3)
``` bash
$ composer require gregoriohc/static-cache, (*4)
## Usage
### Checking for item existence
``` php
if (Cache::has('key')) {
// ...
}
Storing item
``` php
Cache::set('key', 'value');, (*5)
### Retrieving item
``` php
$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:, (*6)
``` php
$value = Cache::get('key', 'default');, (*7)
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:
``` php
Cache::get('key', function() {
return 'value';
});
Retrieve and store item
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:, (*8)
``` php
Cache::remember('key', function() {
return 'value';
});, (*9)
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.
### Removing item
``` php
Cache::forget('key');
Testing
bash
$ composer test
, (*10)
Change log
Please see CHANGELOG for more information on what has changed recently., (*11)
Contributing
Please see CONTRIBUTING for details., (*12)
Security
If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker., (*13)
Socialware
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., (*14)
Credits
License
The MIT License (MIT). Please see License File for more information., (*15)