Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to store a cache item with a tag.
Laravel
Cache::tags('[1]')->put('key', 'value', 60);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method other than tags() to assign tags.
Passing an array instead of a string for a single tag.
✗ Incorrect
The tags method accepts the tag name as a string to group cache items.
2fill in blank
mediumComplete the code to retrieve a cached item with a tag.
Laravel
$value = Cache::tags('users')->[1]('key');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
put instead of get to retrieve data.Using
forget which deletes the cache.✗ Incorrect
The get method retrieves the cached value by key.
3fill in blank
hardFix the error in the code to clear all cache items with the 'users' tag.
Laravel
Cache::tags('users')->[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
clear which is not a valid method.Using
forget which only deletes one key.✗ Incorrect
The flush method clears all cache items for the given tags.
4fill in blank
hardFill both blanks to store a cache item with multiple tags.
Laravel
Cache::tags([[1], [2]])->put('key', 'value', 120);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing tags as a comma-separated string instead of an array.
Using invalid tag names.
✗ Incorrect
Multiple tags are passed as an array of strings to the tags method.
5fill in blank
hardFill all three blanks to retrieve a cached item with multiple tags and a default value.
Laravel
$value = Cache::tags([[1], [2]])->get('key', [3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not passing tags as an array.
Omitting the default value parameter.
✗ Incorrect
The get method accepts a default value returned if the key is missing. Multiple tags are passed as an array.