我使用带有@Cacheable和@CachePut注解的内置缓存的Spring。
我的@Service中有两个方法,一个用于将值保存到数据库中,第二个用于从数据库中获取值。它们都使用缓存。
@CachePut(key = "#code")
MyObject saveMyObject(MyObject o, String code) {
return dao.save(o);
}
@Cacheable(key = "#code")
MyObject getMyObject(String code) {
return dao.getMyObject(code);
}在保存对象时,我想把它放到另一个缓存中,例如
@CachePut(key = "'TMP_'.concat(#code)")但是我不能在saveMyObject方法上使用两个@CachePut注解。
我该怎么办?
发布于 2017-01-20 23:58:26
您可以使用org.springframework.cache.annotation.Caching注释对CachePut进行分组:
@Caching( put = {
@CachePut(key = "#code"),
@CachePut(key = "'TMP_'.concat(#code)")
})
MyObject saveMyObject(MyObject o, String code) {
return dao.save(o);
}https://stackoverflow.com/questions/41767335
复制相似问题