Performance: Cache tags
Cache tags affect how efficiently cached data is invalidated and retrieved, impacting server response time and perceived page speed.
Jump into concepts and practice - no test required
Cache::tags(['users', 'posts'])->flush(); // clears only tagged cache entries
Cache::flush(); // clears entire cache indiscriminately
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full cache flush | N/A | N/A | N/A | [X] Bad |
| Cache tags flush | N/A | N/A | N/A | [OK] Good |
cache tags in Laravel?tags() method accepts an array of tags before calling put().Cache::tags([...])->put(key, value, time).Cache::tags(['products'])->get('item_1'); after Cache::tags(['products'])->flush(); is called?Cache::tags(['products'])->put('item_1', 'Book', 600);
Cache::tags(['products'])->flush();
$value = Cache::tags(['products'])->get('item_1');
echo $value ?? 'Not found';flush() on a tag clears all cached items under that tag.get('item_1') returns null, so the null coalescing operator outputs 'Not found'.Cache::tags('sessions')->put('session_1', 'data', 120);
Cache::tags(['sessions'])->flush();tags() method requires an array of tags, not a string.