artdevue/fcache

Driver file cache, separation key-folder, Laravel 4 integration

dev-master 2014-06-26 09:52 UTC

This package is auto-updated.

Last update: 2024-04-16 22:57:15 UTC


README

========

File cache driver distrubutes cache to folders depending to key-parameter. This is Laravel 4 integration of Fcache.

Quick Start

You can install this Fcache class quickly and easily with Composer.

Edit your composer.json and add next:

"artdevue/fcache": "dev-master"

Run Composer to install or update the new dependencies:

$ composer update

Laravel 4 Integration

The Fcache Cache class supports Laravel 4 integration. Best practice is to add the ServiceProvider of the Intervention Fcache in Laravel 4 installment.

Open your Laravel config file config/app.php and add the following:

In the $providers section add service providers for this package.

'Artdevue\Fcache\FcacheServiceProvider'

Open your Laravel global file start/global.php and add the following lines.

Cache::extend('fcache', function($app)
{
    $store = new Artdevue\Fcache\Fcache;
    return new Illuminate\Cache\Repository($store);
});

Usage

Open your Laravel config file config/cache.php and change driver to fcache.

'driver' => 'fcache',

Note! All commands are identical to the driver file cache, except forget

To create a directory cache it is enough to separate the slash key directory, the file will be the last word.

For example, create the key folder/onesubfolder/onefile.

Cache::put('folder/onesubfolder/onefile', 'value', $minutes);

The system automatically will create subfolders - folder and onesubfolder, and the file onefile.cache

folder
	onesubfolder
		onefile.cache
		twofile.cache
	twosubfolder
		onefile.cache
		twofile.cache
file.cache

With the file cache Fcache you can delete the entire cache, and the cache folder. To delete a file folder/onesubfolder/onefile.cache

Cache::forget('folder/onesubfolder/onefile');

If you need to remove all the files in a directory folder/onesubfolder, then change the key to folder/onesubfolder.

Cache::forget('folder/onesubfolder');

You can group your cache folders, it gives you ability to delete the whole group cache files.

Using tags

Also file driver Fcache works with Tags. When you add a cache, you can use comma-separated parameter tags. Example:

Cache::tags('country,all')->put('key', 'value', $minutes);

or

$value = Cache::tags('users,all')->rememberForever('users', function()
{
   return DB::table('users')->get();
});

Now you can easily remove any cache tag. For example, to delete the cache tag with the users:

Cache::forgetTags('users');

Note! If you want to delete the cache with different tags, assign comma-separated tags. For example:

Cache::forgetTags('users,all');

Authors

687474703a2f2f7777772e67726176617461722e636f6d2f6176617461722f33396566316337343064656666373062303534633164396165386638366430323f733d3630Valentin Rasulov
artdevue.com
http://artdevue.com