I'm using Spring with build-in cache using @Cacheable and @CachePut annotations.
I have 2 methods in my @Service, one to save value in database, second to get value from database. Both of them uses cache.
@CachePut(key = "#code")
MyObject saveMyObject(MyObject o, String code) {
return dao.save(o);
}
@Cacheable(key = "#code")
MyObject getMyObject(String code) {
return dao.getMyObject(code);
}
While saving object I would like to put it in another cache e.g.
@CachePut(key = "'TMP_'.concat(#code)")
but I can't use two @CachePut annotations on saveMyObject method.
What should I do?
You can use org.springframework.cache.annotation.Caching annotation to group your CachePut:
@Caching( put = {
@CachePut(key = "#code"),
@CachePut(key = "'TMP_'.concat(#code)")
})
MyObject saveMyObject(MyObject o, String code) {
return dao.save(o);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With