The tags() method requires an array of tags, not a string.
Step 2: Identify the incorrect usage
Passing a string 'sessions' instead of ['sessions'] causes an error.
Final Answer:
Using string instead of array in tags() method -> Option B
Quick Check:
tags() needs array, not string [OK]
Hint: Always pass array to tags() [OK]
Common Mistakes:
Passing single string instead of array
Thinking flush() is disallowed
Assuming put() needs closure
5. You want to cache user profile data and product data separately but clear both caches together when needed. Which is the best way to use cache tags in Laravel to achieve this?
hard
A. Tag user profiles with ['users'] and products with ['products'], then flush both tags separately
B. Use no tags and clear cache manually by keys
C. Tag both user profiles and products with ['app_data'], then flush this tag to clear all
D. Tag user profiles with ['users'] and products with ['products'], then flush(['users', 'products'])
Solution
Step 1: Understand grouping with tags
To clear multiple cache groups together, use a common tag for both.
Step 2: Apply a shared tag
Tag both user and product caches with a shared tag like 'app_data' to flush all at once.
Final Answer:
Tag both user profiles and products with ['app_data'], then flush this tag to clear all -> Option C
Quick Check:
Shared tag groups caches for joint flush [OK]
Hint: Use shared tag to clear multiple caches together [OK]
Common Mistakes:
Flushing tags separately instead of shared tag
Not tagging caches for group clearing
Trying to flush multiple tags in one call incorrectly