javadoc toexpireAfterAccess
方法说:
指定在条目创建、最近一次替换其值或最后一次访问后经过固定持续时间后,应自动从缓存中删除每个条目。访问时间由所有缓存读取和写入操作(包括 Cache.asMap().get(Object) 和 Cache.asMap().put(K, V))重置,但不通过对 Cache 的集合视图的操作重置。地图
我有以下代码:
Cache<String, String> cache = CacheBuilder.newBuilder()
.expireAfterAccess(2, TimeUnit.SECONDS)
.build();
ConcurrentMap<String, String> map = cache.asMap();
map.put("a", "12345");
System.out.println("First access: " + map.get("a"));
System.out.println("Second access: " + map.get("a"));
Thread.sleep(1900); //1.9 seconds
System.out.println("Third access: " + map.get("a"));
Thread.sleep(1000); //1 second
System.out.println("Fourth access: " + map.get("a"));
Thread.sleep(1500); //1.5 second
System.out.println("Fivth access: " + map.get("a"));
它的输出是:
First access: 12345
Second access: 12345
Third access: 12345
Fourth access: 12345
Fivth access: 12345
因此,正如我们所看到的,当我们对 collection-view 执行 get 操作时,访问时间也会被重置。在这种情况下,javadoc 中的粗体短语意味着什么?