🔴 Laravel
Beginner
What is the Cache system in Laravel?
Answer
Laravel provides a unified caching API supporting multiple backends. Configure in config/cache.php. Drivers: file, database, redis, memcached, array (in-memory, testing), dynamodb. Common operations: Cache::put("key", $value, now()->addMinutes(60)), Cache::get("key", "default"), Cache::has("key"), Cache::forget("key"), Cache::flush(). The Remember pattern: Cache::remember("users", 3600, fn() => User::all()) — retrieves from cache if exists, otherwise executes the closure and caches the result. Cache::rememberForever("key", $closure) caches indefinitely. Use cache tags with Redis/Memcached to group and invalidate related items. Caching is critical for improving performance of expensive database queries and API calls.