PHP code example of krisanalfa / bono-cache
1. Go to this page and download the library: Download krisanalfa/bono-cache library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
krisanalfa / bono-cache example snippets
'bono.providers' => array(
'\\KrisanAlfa\\Cache\\Provider\\CacheProvider'
),
'cache' => array(
'driver' => 'file',
'path' => __DIR__ . '/../../cache',
'prefix' => 'bono',
)
$app->cache->put('key', 'value', $minutes);
$expiresAt = Carbon::now()->addMinutes(10);
$app->cache->put('key', 'value', $expiresAt); // cache will be expired at 10 minutes later
$app->cache->add('key', 'value', $minutes);
if ($app->cache->has('key'))
{
//
}
$value = $app->cache->get('key');
$value = $app->cache->get('key', 'default');
$value = $app->cache->get('key', function() { return 'default'; });
$app->cache->forever('key', 'value');
$value = $app->cache->remember('users', $minutes, function()
{
return Norm::factory('User')->find();
});
$value = $app->cache->rememberForever('users', function()
{
return Norm::factory('User')->find();
});
$app->cache->forget('key');
$app->cache->tags('people', 'authors')->put('Alfa', $alfa, $minutes);
$app->cache->tags(array('people', 'artists'))->put('Ganesha', $ganesha, $minutes);
$ganesha = $app->cache->tags('people', 'artists')->get('Ganesha');
$alfa = $app->cache->tags(array('people', 'authors'))->get('Alfa');
$app->cache->tags('people', 'authors')->flush();
$app->cache->tags('authors')->flush();