<?php use Illuminate\Support\Facades\Cache; Cache::put('user_count', 15, 10); $value = Cache::get('user_count'); echo $value;
The code stores the value 15 in the cache with the key 'user_count' for 10 seconds. Then it retrieves the value using Cache::get. Since the key exists, it returns 15.
Options B and C are correct. B uses a DateTime instance (now()->addMinutes(5)). C uses 300 seconds (5 * 60 = 5 minutes). Option A uses 5 seconds (too short). Option D uses invalid string syntax.
<?php use Illuminate\Support\Facades\Cache; Cache::put('session_data', ['id' => 1, 'name' => 'Alice'], 1); $value = Cache::get('session_data'); // After 2 minutes $valueAfter = Cache::get('session_data');
The cache was set to expire after 1 second. Retrieving after 2 minutes means the cache expired and returns null.
Cache::remember checks if the key exists. If yes, returns cached value. If no, runs the closure, caches its return value, then returns it.
<?php use Illuminate\Support\Facades\Cache; Cache::put('count', 5, 10); Cache::increment('count'); Cache::increment('count', 3); $count = Cache::get('count'); echo $count;
Initial value is 5. First increment adds 1 (default), second adds 3, total 5 + 1 + 3 = 9.
