Cache tags in Laravel 12 are now officially documented again, as you noticed. Here’s the current status and best practices as of Laravel 12:
1. Supported Drivers
Cache tags only work with the following cache drivers:
redismemcacheddynamodb- (Not supported:
file,database, andarraydrivers)
If you use cache tags with an unsupported driver, Laravel will throw an exception.
2. Issues and Fixes
The main issues reported in the past were related to tag invalidation and performance. The main problematic driver was file (and sometimes database). These problems were a key reason tags disappeared from the documentation.
Since Laravel 12, the framework has:
- Hardened cache tag support specifically for the drivers mentioned above.
- Made it more explicit in the documentation that tags are only for certain drivers.
- Older problems with tag performance and reliability on supported drivers have largely been resolved.
3. When To Use
- If you are using one of the supported drivers (
redisormemcachedare most common), it’s safe and recommended to use cache tags. - Always avoid attempting to use tags on unsupported drivers—this will throw an error.
4. Usage Example
Here’s a basic example for Redis:
Cache::tags(['users', 'admins'])->put('user:1', $user, 3600);
$user = Cache::tags(['users', 'admins'])->get('user:1');
// To flush all cache items tagged with "users"
Cache::tags(['users'])->flush();
5. Summary
Cache tags are safe and encouraged to use in Laravel 12 as long as you stick to supported cache drivers (like Redis). There’s no lingering warning about bugs when you do this, and they’re a powerful way to manage grouped cache entries.
References:
In summary:
Use cache tags on supported drivers in Laravel 12 — they are fully supported and stable in those contexts. For file, database, or array drivers, do not use tags.