use*_*048 2 java spring spring-cache
我正在使用Spring内置缓存使用@Cacheable和@CachePut注释.
我的@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);
}
Run Code Online (Sandbox Code Playgroud)
在保存对象的同时,我想把它放在另一个缓存中,例如
@CachePut(key = "'TMP_'.concat(#code)")
Run Code Online (Sandbox Code Playgroud)
但我不能@CachePut在saveMyObject方法上使用两个注释.
我该怎么办?
您可以使用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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2162 次 |
| 最近记录: |