使用CachePut和可缓存的

问题描述 投票:-1回答:1

我有以下两种方法。一种方法使用@CachePut注释,另一种方法使用@Cacheable注释。它们都使用相同的key。根据其他帖子的一些答案,我发现@cacheput替换了该值。如果是这种情况,如果文档中的字段之一有更新,是否将对相同的id执行@Cacheable注释的方法。

@CachePut(value="testcache",key="#document.id")
public Document update(Document document){
// code to update db
return document
}

@Cacheable(value="testcache")
public Document getDocument(String id){
// query database and fetch document
 return document
}
spring-boot hazelcast spring-cache
1个回答
0
投票

仅在键在缓存中没有值时执行带有@Cacheable注释的方法。因此,@ CachePut是否更新了文档都没有关系。只要文档在缓存中,getDocument(id)就不会进入数据库。 (CachePut为您执行数据库更新)

© www.soinside.com 2019 - 2024. All rights reserved.