当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Does cache2k put() update the expiry time

问题描述:

I can't find an answer in the API docs, that's why I'd like to ask here:

Given I have a cache2k cache

import org.cache2k.Cache;

import org.cache2k.CacheBuilder;

import java.util.concurrent.TimeUnit;

....

Cache<String, Integer> cache =

CacheBuilder.newCache(String.class, Integer.class)

.expiryDuration(1, TimeUnit.MINUTES)

and put an item in it

cache.put("item", 1)

the expiry time of this item is one minute. After 30 seconds I update this item with

cache.put("item", 0)

is the expiry time of this item now approximatly 30 second or one minute again?

Every helpful comment is very appreciated. Maybe I missed the answer in the docs or there is some standard I don't know about...

Regards

globalworming

网友答案:

The expiry duration is the time between an entry is stored in the cache (e.g. via put or a get() and read through) until the entry is considered expired. Expired entries are no longer valid and not returned any more by the cache. Whether an expired entry is removed from the internal cache data depends on other configurations.

Some caches make a difference between the expiry time after a new entry and an update. In cache2k this is identical.

So, after the second put() the expiry is reset and the entry expires after one minute.

分享给朋友:
您可能感兴趣的文章:
随机阅读: