| title | Cache |
|---|---|
| description | Caching data in your console application |
Laravel's cache is available in every Laravel Zero application — there is no component to install.
By default, Laravel Zero uses the array cache driver. Because the array driver stores items in memory, cached values live for the duration of the currently executing command and are discarded when the process exits. This is a sensible default for a console application: the Cache facade works out of the box, and nothing is written to disk.
If you would like your cached items to survive between runs, you should publish the cache configuration file:
php application config:publish cacheThen, choose one of the drivers supported by Laravel — such as file, database, or redis — within the config/cache.php configuration file:
'default' => env('CACHE_STORE', 'file'),Note: Drivers such as
databaseandredisrequire the corresponding database component to be installed.
You may interact with the cache using the Cache facade:
use Illuminate\Support\Facades\Cache;
Cache::put('movies', $movies, $seconds = 600);
$movies = Cache::get('movies');The remember method is particularly useful in console applications, since it allows you to retrieve an item from the cache, or compute and store it when it is missing:
$movies = Cache::remember('movies', 600, function () {
return $this->tmdb->popular();
});Full details on the available cache methods are available in the cache documentation on the Laravel website.