首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Boot与caffeine同步缓存不起作用

Spring Boot与caffeine同步缓存不起作用
EN

Stack Overflow用户
提问于 2018-04-26 15:24:53
回答 1查看 3.2K关注 0票数 1

我使用caffeine 2.6.2作为缓存提供者的Spring Boot 1.5.12.RELEASE

我的一个服务中有一个方法:

代码语言:javascript
复制
@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,则会计算两次该值:

代码语言:javascript
复制
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不工作了。我是不是遗漏了什么?

编辑:主类注释:

代码语言:javascript
复制
@SpringBootApplication(exclude = [ElastiCacheAutoConfiguration::class])
@EnableSwagger2
@EnableScheduling
@EnableCaching
@EnableTransactionManagement
class Application
EN

回答 1

Stack Overflow用户

发布于 2019-11-15 08:23:06

这很荒谬但是..。尝试更改缓存名称。

我只是遇到了同样的问题,不知道我的配置出了什么问题。因此,我更改了缓存的名称-它神奇地工作。太傻了..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50037154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档