calgamo / cache
Cache library for Calgamo Framework.
Installs: 2 623
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- ext-json: *
- calgamo/config: ~0.2
- psr/simple-cache: ^1.0
Requires (Dev)
- mikey179/vfsstream: 1.3.*
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^6.3.0
README
Description
Calgamo/Cache is a cache library for calgamo framework.
Feature
- PSR16: SimpleCache compliant
- File cache
- Array cache
Demo(FileCache)
config
$config = [ 'cache' => [ 'root' => '/path/to/cache', 'expire' => 5, // expires 5 seconds after cache item is set ] ];
get/set
$cache = new FileCache($config); $cache->set('my favorite artist', 'stevie wonder'); echo $cache->get('my favorite artist'); // stevie wonder $cache->set('my favorite artist', 'justin bieber'); echo $cache->get('my favorite artist'); // justin bieber
expire
$cache = new FileCache($config); $cache->set('my favorite artist', 'stevie wonder'); echo $cache->get('my favorite artist'); // stevie wonder sleep(6); echo $cache->get('my favorite artist'); // $cache->set('my favorite artist', 'stevie wonder', 10); sleep(6); echo $cache->get('my favorite artist'); // stevie wonder
delete
$cache = new FileCache($config); $cache->set('my favorite artist', 'stevie wonder'); echo $cache->get('my favorite artist'); // stevie wonder $cache->delete('my favorite artist'); echo $cache->get('my favorite artist'); //
clear
$cache = new FileCache($config); $cache->set('my favorite artist', 'stevie wonder'); $cache->set('my favorite movie', 'Jurassic Park'); echo $cache->get('my favorite artist'); // stevie wonder echo $cache->get('my favorite movie'); // Jurassic Park $cache->clear(); echo $cache->get('my favorite artist'); // echo $cache->get('my favorite movie'); //
get multiple cache
$cache = new FileCache($config); $cache->set('my favorite artist', 'stevie wonder'); $cache->set('my favorite movie', 'Jurassic Park'); $values = $cache->getMultiple([ 'my favorite artist', 'my favorite movie' ]); echo print_r($values, true); // Array // ( // [my favorite artist] => stevie wonder // [my favorite movie] => Jurassic Park // )
set multiple cache
$cache = new FileCache($config); $cache->setMultiple([ 'my favorite artist' => 'stevie wonder', 'my favorite movie' => 'Jurassic Park', ]); echo $cache->get('my favorite artist'); // stevie wonder echo $cache->get('my favorite movie'); // Jurassic Park
array cache
$cache = new ArrayCache($config); $cache->set('my favorite artist', 'stevie wonder'); echo $cache->get('my favorite artist'); // stevie wonder sleep(6); echo $cache->get('my favorite artist'); //
Usage
1. Make config array
- cache/root is required for FileCache
- cahe/expire is optional(unit: seconds)
2. Create cache object
- pass config array to the constructor
3. Set or get cache
- use get() method to get cache item
- use set() method to update cache item
Requirement
PHP 7.1 or later
Installing calgamo/cache
The recommended way to install calgamo/cache is through Composer.
composer require calgamo/cache
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
License
This library is licensed under the MIT license.
Author
Disclaimer
This software is no warranty.
We are not responsible for any results caused by the use of this software.
Please use the responsibility of the your self.