开发者

what mean a element expired in Ehcache

when I use the Ehcache ,there is something that I can't understand,what means that a elements is expired,if a element is expired it means that the cache will clear the element and it will don't exisit any more? or it also existed but you couldn't get it. here is the code i write , I get data from xml and judge like this

public Object get(Class classObj, String nodeName, String fileName) {
    Object obj = null;

    if (!ehcacheVindicator.getCache().isDisabled()&&ehcacheVindicator.getC开发者_开发知识库ache().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;
}

couldn't tell me whether it is wrong?


You can set your ehcache to cache objects for a limited period of time with the attribute timeToLiveSeconds (in the xml configuration file)

timeToLiveSeconds: Sets the time to live for an element before it expires. i.e. The maximum time between creation time and when an element expires. Is only used if the element is not eternal. Optional attribute. A value of 0 means that and Element can live for infinity. The default value is 0.

More info here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜