java - Ehcache 中的元素过期是什么意思

标签 java ehcache

当我使用Ehcache时,有一点我无法理解,元素过期是什么意思,如果元素过期就意味着缓存将清除该元素并且不再存在?或者它也存在但你无法得到它。这是我写的代码,我从xml获取数据并这样判断

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: 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.

更多信息here

关于java - Ehcache 中的元素过期是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4447733/

相关文章:

java - 当 Terracotta 服务器用作带 Hibernate 的 EHCache 的后端时,它会做什么?

java - 在没有 XML 配置的情况下将 Ehcache CacheManager (v 3.x) 转换为 Spring CacheManager

java - 如何将数组复制到phonegap中的文件中?

java - 使用 iText 2.1.7 合并大型 PDF

java - 使用正则表达式从文本文件中删除样式标签

java - 从 H2 中选择包含空格的列名称

grails - 如何在 Grails 中配置分布式缓存(没有 Terracota)

Java Web 应用程序无法连接到 AWS RDS 数据库实例

java - Spring 的 @Cacheable 放在返回列表的方法上时会做什么?

grails - 初始化高速缓存导致 “grails run-app”失败时发生异常