Simple cache service using SQLite to reduce multiple db queries.
- default cache time: 60mins
- default cache path: Carloshb\CacheService\Driver
Install using composer
composer require carloshb/cache-service 0.2.*
Or clone in or project.
Add PHP env:
$_ENV['cache_time'] = 10; // minutes
$_ENV['cache_path'] = 'yor/storage/path';
The method resolve() returns an instance of Cache class and generate or update the key sent with the callback return. First parameter is the key, a string. Second parameter is the callback, a function returning array with expected results. Third parameter is optional, for set n minutes for cache.
$cache = new \Carloshb\CacheService\Cache();
$cache->resolve('getInfo', function(){
return array(
'name' => 'Carlos Henrique Bernardes',
'email' => '[email protected]'
);
});
Use after resolve() to get a content of cache, the method returns a json.
$cache = new \Carloshb\CacheService\Cache();
$content = $cache->resolve('getInfo', function(){
return array(
'name' => 'Carlos Henrique Bernardes',
'email' => '[email protected]'
);
})->getCacheContent();
Use this method to force cache destroy using the key name.
$cache = new \Carloshb\CacheService\Cache();
$response = $cache->destroy('getInfo');
var_dump($response); // true or false