0
0
Laravelframework~10 mins

Storing and retrieving cache in Laravel - Interactive Code Practice

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 the cache for 10 minutes.

Laravel
Cache::put('key', 'value', [1]);
Drag options to blanks, or click blank then click option'
A600
B6000
C10
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 directly instead of seconds.
Using 6000 which is too long.
Confusing minutes with seconds.
2fill in blank
medium

Complete the code to retrieve a cached value by its key.

Laravel
$value = Cache::[1]('key');
Drag options to blanks, or click blank then click option'
Aget
Bsave
Cput
Dstore
Attempts:
3 left
💡 Hint
Common Mistakes
Using put which stores data.
Using store which is not a valid method.
Using save which does not exist in Cache facade.
3fill in blank
hard

Fix the error in the code to remember a value in the cache for 5 minutes.

Laravel
Cache::remember('key', [1], function() {
    return 'value';
});
Drag options to blanks, or click blank then click option'
A30
B3000
C300
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3000 which is too long.
Using 30 which is too short.
Using 3 which is too short.
4fill in blank
hard

Fill both blanks to check if a cache key exists and then retrieve it.

Laravel
if (Cache::[1]('key')) {
    $value = Cache::[2]('key');
}
Drag options to blanks, or click blank then click option'
Ahas
Bget
Cput
Dexists
Attempts:
3 left
💡 Hint
Common Mistakes
Using put instead of has or get.
Using exists which is not a Laravel Cache method.
5fill in blank
hard

Fill all three blanks to store a value forever and then retrieve it with a default fallback.

Laravel
$value = Cache::[1]('key', 'default');
Cache::[2]('key', 'value');
Cache::[3]('key', 'value');
Drag options to blanks, or click blank then click option'
Aget
Bforever
Cput
Dremember
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up put and forever.
Using remember incorrectly here.