Java Ehcache中的元素过期是什么意思
当我使用Ehcache时,有一些我不明白的事情,什么意味着元素过期,如果元素过期,则意味着缓存将清除元素,并且不再存在?或者它也存在,但你无法得到它。这是我写的代码,我从xml中获取数据,然后像这样判断Java Ehcache中的元素过期是什么意思,java,ehcache,Java,Ehcache,当我使用Ehcache时,有一些我不明白的事情,什么意味着元素过期,如果元素过期,则意味着缓存将清除元素,并且不再存在?或者它也存在,但你无法得到它。这是我写的代码,我从xml中获取数据,然后像这样判断 public Object get(Class classObj, String nodeName, String fileName) { Object obj = null; if (!ehcacheVindicator.getCache().isDisabled()&
public Object get(Class classObj, String nodeName, String fileName) {
Object obj = null;
if (!ehcacheVindicator.getCache().isDisabled()&&ehcacheVindicator.getCache().isKeyInCache(nodeName)) {
Element element = ehcacheVindicator.getCache().get(nodeName);
if (ehcacheVindicator.getCache().isExpired(element)){
obj = readObject(classObj, fileName, nodeName);// read object from xml file
updateObject(nodeName,obj);
}
else
obj = getObject(nodeName); // get object from cache
} else {
obj = readObject(classObj, fileName, nodeName); // read object from
// xml file
addObject(nodeName, obj); // add object to cache
}
return obj;
}
无法告诉我是否错误?您可以使用属性
timeToLiveSeconds
(在xml配置文件中)将ehcache设置为在有限的时间内缓存对象
timeToLiveSeconds:
设置元素过期前的生存时间。
i、 e.从创建时间到创建元素之间的最长时间
到期。
仅当元素不是永恒的时才使用。
可选属性。值为0表示和元素可以生存
无穷
默认值为0
更多信息您可以使用属性
timeToLiveSeconds
(在xml配置文件中)将ehcache设置为在有限的时间段内缓存对象
timeToLiveSeconds:
设置元素过期前的生存时间。
i、 e.从创建时间到创建元素之间的最长时间
到期。
仅当元素不是永恒的时才使用。
可选属性。值为0表示和元素可以生存
无穷
默认值为0
更多信息