📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Laravel Framework Caching

Caching

5 min read Quiz at the end
Cache expensive queries with Cache::remember() using file, Redis, or database drivers.

Caching

use IlluminateSupportFacadesCache;

// Store
Cache::put("key", "value", now()->addHours(1));
Cache::forever("key", "value");
Cache::set("key", "value", 3600);  // seconds

// Retrieve
$val = Cache::get("key");
$val = Cache::get("key", "default");

// Remember — cache-or-fetch pattern
$users = Cache::remember("all_users", 3600, fn() => User::all());
$data  = Cache::rememberForever("config", fn() => Config::all());

// Delete
Cache::forget("key");
Cache::flush(); // clear all

// Tags (Redis/Memcached)
Cache::tags(["users"])->put("user_1", $user, 3600);
Cache::tags(["users"])->flush();

// .env
CACHE_DRIVER=redis  // file, database, redis, memcached
Topic Quiz · 2 questions

Test your understanding before moving on

1. Which method fetches from cache or executes a closure?
💡 Cache::remember() returns cached value or runs the closure and caches the result.
2. Cache::forever() stores a value for how long?
💡 Cache::forever() stores without expiry until Cache::forget() is called.