@CacheEvict should allow multiple key values [SPR-10958]
See original GitHub issueAshot Golovenko opened SPR-10958 and commented
Currently you can evict only one or all elements in a single cache region. Allowing something like
@CacheEvict(value = "userCache", key = {"key1", "key2"})
would be really handful.
Affects: 3.2.4
12 votes, 14 watchers
Issue Analytics
- State:
- Created 10 years ago
- Comments:20
Top Results From Across the Web
Cache evict on one of multiple keys - java - Stack Overflow
In general a cache acts like a hash table, you can only operate on a unique key. Selecting everything which belongs to a...
Read more >Cache Eviction in Spring Boot - Baeldung
Here's how we can implement these two cache eviction mechanisms in code. ... @CacheEvict(value = "first", key = "#cacheKey") public void ...
Read more >29. Cache Abstraction - Spring
For caching declaration, the abstraction provides two Java annotations: @Cacheable and @CacheEvict which allow methods to trigger cache population or cache ...
Read more >Spring Boot Caffeine 기본 세팅
value = cache 저장소, key = 저장소 key값 @Cacheable(value ... @CacheEvict should allow multiple key values [SPR-10958] · Issue #15586 ...
Read more >Spring Cache Evict - LogicBig
By default, @CacheEvict will cause the target cache to be removed after ... This allows new value to be cached via @Cacheable after...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Kyle Lieber commented
We could really use this functionality as well. I think the suggestions made by
@jkuhs
would work. Here my scenario if it helps:We have a
Policy
and aProduct
.I have a
Policy
which is identified by apolicyId
and eachPolicy
can have multipleProducts
which are identified by thepolicyId
and theproductCode
.So I have a
ProductService
with a method for getting a product bypolicyId
andproductCode
.Then I have a
PolicyService
which has a method for deleting aPolicy
when given thepolicyId
.The
PolicyService#deletePolicy
will also delete all products for that policy but I have no way to clear theproducts
cache for that policy.My workaround options are:
Johannes Kuhs commented
For more advanced caching scenarios, some concept of having multiple keys is definitely necessary in my opinion. I’m not sure it needs to be in the form of allowing multiple
key
values though. Thekey
is used for retrieving a cache entry but really we just need a way to evict specific entries. So instead, it might make more sense to add a newevictKeys
parameter.evictKeys
simply point to thekey
and can thus be used to evict the actual entry.Another use-case for this kind of functionality would be the caching of different product information. A product might have skus, images, prices, features, facets, and other information attached to it that require more expensive operations (e.g. looping through all images to find a certain image type + view, getting a specific customer price, creating a distinct set of facets across skus, etc.). It would be nice to be able to cache the results of these kind of operations and simply evict them based on the product ID when the product is updated.
Updating the existing annotations to support this could look like this: