【发布时间】:2016-11-03 16:51:53
【问题描述】:
我有以下 spring 缓存配置:
spring.cache.guava.spec: expireAfterWrite=1s
那我测试一下:
@Test
public void test_not_work() {
callCachedMethod(..);
sleep(2s);
callCachedMethod(..);
expect("real method called TWO times");
// because cache should be expired after 1s
// It DOESN'T work, real method only called once
}
@Test
public void test_works() {
callCachedMethod(..);
sleep(2s);
callCachedMethod(..);
sleep(2s);
callCachedMethod(..);
expect("real method called THREE times");
// because cache should be expired after 1s
// IT WORKS!!
}
谁能解释一下?
【问题讨论】:
-
一方面,你确定 Guava 真的被使用了吗?与其粘贴我们没有机会运行的测试,不如分享一个重现问题的项目。这将更容易解释发生了什么。
-
请多解释问题,你不写问题
标签: spring spring-boot guava spring-cache google-guava-cache