Complete the code to store a value in Laravel cache.
Cache::put('key', 'value', [1]);
The third parameter is the number of minutes to cache the value. Using 60 caches it for one hour.
Complete the code to retrieve a cached value or run a closure if not cached.
$value = Cache::remember('key', 30, function() { return [1]; });
The closure returns the value to cache if the key is missing. Here, it returns 'default value'.
Fix the error in the code to check if a cache key exists.
if (Cache::[1]('user_123')) { return Cache::get('user_123'); }
The correct method to check if a cache key exists is has.
Fill both blanks to cache a database query result for 10 minutes.
$users = Cache::[1]('users', [2], function() { return DB::table('users')->get(); });
Use remember to cache the result for 10 minutes.
Fill all three blanks to remove a cache key and then check if it still exists.
Cache::[1]('session_45'); if (!Cache::[2]('session_45')) { return '[3]'; }
forget removes the cache key, has checks existence, and 'deleted' is the message returned.
