-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It isn't possible to access an entry tagged with multiple tags by providing just one of this tags [Cache Tags] #25234
Comments
This is unfortunately how it works. If you want to propose a different behavior it's best to propose an idea at https://github.com/laravel/ideas |
Looked into this as it would have been a useful feature for something I was trying to do. The way the cache currently works in Laravel is quite far from this working because in the key names it has a hash of all the tags combined.
So the above would create 2 different records, but we'd need this to only create 1 record for it be accessible when only having some of the tags. Possible with Redis but would be a pretty breaking change with how Laravel currently works. |
I faced the same problem and after spending a lot of time searching I found the problem The problem is in this line
It leads to excessive duplication of data in the cache when you use multiple tags. If you return only $key , everything works as expected. After testing for a long time, I did not find any side effects
You can copy this modified file with the fix Overrides/TaggedCache.php or just install my kolirt/laravel-cacheable package if it's useful to you And then you need to add the following code to composer.json and specify either your path to the new file or use the file from the package if you installed it {
"autoload": {
"exclude-from-classmap": [
"vendor/laravel/framework/src/Illuminate/Cache/TaggedCache.php"
],
"files": [
"vendor/kolirt/laravel-cacheable/src/Overrides/TaggedCache.php"
// or your path
"app/your-path/TaggedCache.php"
]
}
} After updating the composer ( |
https://laravel.com/docs/5.6/cache#cache-tags
Description:
It is possible to invalidate all entries tagged with multiple tags by providing just one of this tags, but to access an entry you have to pass all tags in the exact order. It would be great if you could access all entries tagged with multiple tags by providing just one of this tags.
Example for my case:
I'm creating a package to cache eloquent queries.
Storing
List of authors
Cache::tags(['author-1', 'author-2', 'author-3', 'author-all'])->put('List'.$checksum, $authorList, $minutes);
Invalidate
Invalidate author (for example update author)
Cache::tags(['author-1'])->flush();
Invalidate list (for exampe I added a new author)
Cache::tags(['author-all'])->flush();
Accessing
To get the list I have to know all tags:
Cache::tags(['author-1', 'author-2', 'author-3', 'author-all'])->get('List'.$checksum);
Better solution
Cache::tags(['author-all'])->get('List'.$checksum);
The text was updated successfully, but these errors were encountered: