Package Data | |
---|---|
Maintainer Username: | krisanalfa |
Maintainer Contact: | krisan47@gmail.com (Krisan Alfa Timur) |
Package Create Date: | 2014-03-11 |
Package Last Update: | 2014-07-01 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-19 03:21:00 |
Package Statistics | |
---|---|
Total Downloads: | 18 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 0 |
#BonoCache Laravel Cache for Bono PHP Framework.
##Configuration Add these lines to your configuration file.
'bono.providers' => array(
'\\KrisanAlfa\\Cache\\Provider\\CacheProvider'
),
'cache' => array(
'driver' => 'file',
'path' => __DIR__ . '/../../cache',
'prefix' => 'bono',
)
The configuration takes three settings, they are driver
, path
, and prefix
.
####Driver This option controls the default cache "driver" that will be used when using the Caching library. Of course, you may use other drivers any time you wish.
Supported Driver:
file
, array
, apc
norm
, redis
, memcached
####Path
When using the file
cache driver, we need an absolute location where the cache files may be stored.
##Cache Usage
$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);
The add
method will return true
if the item is actually added to the cache.
Otherwise, the method will return false
.
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');
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 $app->cache->remember
method:
$value = $app->cache->remember('users', $minutes, function()
{
return Norm::factory('User')->find();
});
You may also combine the remember
and forever
methods:
$value = $app->cache->rememberForever('users', function()
{
return Norm::factory('User')->find();
});
Note that all items stored in the cache are serialized, so you are free to store any type of data.
$app->cache->forget('key');
Note: Cache tags are not supported when using the
file
cache drivers. Furthermore, when using multiple tags with caches that are stored "forever", performance will be best with a driver such asmemcached
, which automatically purges stale records.
Cache tags allow you to tag related items in the cache, and then flush all caches tagged with a given name.
To access a tagged cache, use the tags
method:
You may store a tagged cache by passing in an ordered list of tag names as arguments, or as an ordered array of tag names.
$app->cache->tags('people', 'authors')->put('Alfa', $alfa, $minutes);
$app->cache->tags(array('people', 'artists'))->put('Ganesha', $ganesha, $minutes);
You may use any cache storage method in combination with tags, including remember
, forever
, and rememberForever
.
You may also access cached items from the tagged cache, as well as use the other cache methods such as increment
and decrement
:
To access a tagged cache, pass the same ordered list of tags used to save it.
$ganesha = $app->cache->tags('people', 'artists')->get('Ganesha');
$alfa = $app->cache->tags(array('people', 'authors'))->get('Alfa');
You may flush all items tagged with a name or list of names.
For example, this statement would remove all caches tagged with either people
, authors
, or both.
So, both "Ganesha" and "Alfa" would be removed from the cache:
$app->cache->tags('people', 'authors')->flush();
In contrast, this statement would remove only caches tagged with authors
, so "Alfa" would be removed, but not "Ganesha".
$app->cache->tags('authors')->flush();
##Read More For more information about Laravel Cache, read this.