我使用caffeine 2.6.2作为缓存提供者的Spring Boot 1.5.12.RELEASE。
我的一个服务中有一个方法:
@Cacheable(cacheNames = [CacheService.MY_CACHE_NAME], sync = true)
fun fetchThing(id: Int, at: OffsetDateTime?): Thing? {
LOGGER.debug("################### $id $at #############")
// some network operation
LOGGER.debug("################### $id $at IS DONE #############")
return thing
}我希望只看到第一个日志一次,但如果在第一个调用解析之前再次调用fetchThing,则会计算两次该值:
09:18:34.657 [XNIO-2 task-11] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null #############
09:18:34.673 [XNIO-2 task-12] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null #############
09:18:36.025 [XNIO-2 task-11] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null IS DONE #############
09:18:36.030 [XNIO-2 task-12] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null IS DONE #############如果我再次调用这个函数,我看不到任何日志,所以缓存正在工作。
所以看起来sync不工作了。我是不是遗漏了什么?
编辑:主类注释:
@SpringBootApplication(exclude = [ElastiCacheAutoConfiguration::class])
@EnableSwagger2
@EnableScheduling
@EnableCaching
@EnableTransactionManagement
class Application发布于 2019-11-15 08:23:06
这很荒谬但是..。尝试更改缓存名称。
我只是遇到了同样的问题,不知道我的配置出了什么问题。因此,我更改了缓存的名称-它神奇地工作。太傻了..。
https://stackoverflow.com/questions/50037154
复制相似问题