我有以下弹簧缓存配置:
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!!
}
有人可以解释一下吗?