gregoriohc / static-cache
PHP simple static cache class
Requires
- php: ~5.6|~7.0|~8.0
Requires (Dev)
- phpunit/phpunit: >=4.0
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-10-09 02:41:38 UTC
README
PHP simple static cache class
Install
Via Composer
$ composer require gregoriohc/static-cache
Usage
Checking for item existence
if (Cache::has('key')) { // ... }
Storing item
Cache::set('key', 'value');
Retrieving item
$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'; });
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:
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.
Removing item
Cache::forget('key');
Testing
$ composer test
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker.
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.
Credits
License
The MIT License (MIT). Please see License File for more information.