Tags don't work in all cache drivers. If you're using 'file' or 'database' as cache driver you'll not be able to use tags.
Thanks for your quick answer.
Actually I'm using file cache driver. Maybe there is another way to solve my problem. I need to group the cache and after i need delete all cache from this group ;)
Well, there seems to be a macro functionality for Cache.
For example, if you wanted to store some User related data in Cache and you need to have a convenient method of invalidating all of the given user caches upon some change you could define:
// app/routes.php OR any other file that gets loaded in app/start/global.php
Cache::macro('purgeUserData',function($user_id){
Cache::forget('user_images'.$user_id);
Cache::forget('user_properties'.$user_id);
Cache::forget('user_orders'.$user_id);
});
and then when you need to delete all user cached data you just call
Cache::purgeUserData($user_id);
This way you can more easily mimick tag-like cache data invalidation. This is not as robust as tags but can be helpful for organizing your cache.
Of course you still need to manually manage cache keys and potentially distinguish them by some id, like $user_id in above example.
i recommend you first check, if using memcached or another driver which supports tags is available on your production server. installing it locally is not hard at all. do not use array driver, it is for testing only.
the solution provided above might backfire hard. what if a user gets deleted before clearing the cache? then it would be impossible to clear the cache related to deleted user.
i'm not saying, that there are no other solutions, but i just went down this road and decided to make cache available only, when tags are present. it just got too messy without them.
what if a user gets deleted before clearing the cache?
The cache will expire, unless it's set to forever
But I totally agree with you @keevitaja. Cache tags make things way more maintainable and hugely minimize potential logic-related bugs.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community