Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lumen file cache driver

I'm in Lumen, inside a Controller, and I would like to cache a computation's result in a simple and easy way, without using database or external services, so I was looking for save the cache in the filesystem. In Laravel's documentation there is cited the file driver:

By default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the filesystem.

And I can see it, configured as Default Cache Store, inside config/cache.php.

In Lumen's documentation i can't see anything about the file driver and I find nothing like the file cache.php inside Lumen installation.

So my question is if I can use the file cache driver in Lumen (by setting CACHE_DRIVER=file) or if it is discouraged, not supported, not implemented or something else?

like image 706
Andrea Avatar asked Dec 30 '15 18:12

Andrea


1 Answers

In Lumen in .env.example you have by default:

CACHE_DRIVER=memcached

So all you need is to change filename from .env.example to .env and set

CACHE_DRIVER=file

If you read Caching in Lumen you'll see in example:

$value = Cache::store('file')->get('foo');

so file driver is supported by Lumen.

If you also read Lumen Configuration you can read here that you can copy configuration files you need (in case you need them) and load them manually. You can see default Luman cache config file here: https://github.com/laravel/lumen-framework/blob/5.1/config/cache.php

like image 127
Marcin Nabiałek Avatar answered Oct 10 '22 23:10

Marcin Nabiałek