0
0
Laravelframework~10 mins

Why caching reduces response times in Laravel - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to store a value in Laravel cache.

Laravel
Cache::put('key', 'value', [1]);
Drag options to blanks, or click blank then click option'
A'60 minutes'
B'forever'
Cnull
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for duration.
Passing null which means no caching.
2fill in blank
medium

Complete the code to retrieve a cached value or run a closure if not cached.

Laravel
$value = Cache::remember('key', 30, function() { return [1]; });
Drag options to blanks, or click blank then click option'
Anull
B'default value'
CCache::get('key')
Dnow()
Attempts:
3 left
💡 Hint
Common Mistakes
Returning null which caches nothing.
Calling Cache::get inside the closure causing recursion.
3fill in blank
hard

Fix the error in the code to check if a cache key exists.

Laravel
if (Cache::[1]('user_123')) { return Cache::get('user_123'); }
Drag options to blanks, or click blank then click option'
Ahas
Bexists
Ccontains
Dcheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exists' which is not a Laravel Cache method.
Using 'contains' or 'check' which do not exist.
4fill in blank
hard

Fill both blanks to cache a database query result for 10 minutes.

Laravel
$users = Cache::[1]('users', [2], function() { return DB::table('users')->get(); });
Drag options to blanks, or click blank then click option'
Aremember
Bput
C10
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'put' which does not return the cached value.
Using 60 minutes instead of 10.
5fill in blank
hard

Fill all three blanks to remove a cache key and then check if it still exists.

Laravel
Cache::[1]('session_45'); if (!Cache::[2]('session_45')) { return '[3]'; }
Drag options to blanks, or click blank then click option'
Aforget
Bhas
Cdeleted
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exists' instead of 'has' to check key.
Returning wrong message string.