【问题标题】:hibernatetemplate clear ehcache?hibernatetemplate清除ehcache?
【发布时间】:2009-12-01 07:19:55
【问题描述】:
<ehcache>
    <cache name="query.ContactInfoList"
        maxElementsInMemory="200"
        eternal="true"
        overflowToDisk="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"
    />
</ehcache>

public List getContactInfoList(){
    hibernateTemplate.setCacheQueries(true);
    hibernateTemplate.setQueryCacheRegion("query.ContactInfoList");
    List list = hibernateTemplate.find("from AdoContactInfo a where active = 1");
    hibernateTemplate.setCacheQueries(false);
    return list;
}

我可以知道在调用hibernatetemplate saveupdate时如何清除/刷新 query.ContactInfoList 的缓存

【问题讨论】:

    标签: java hibernate spring ehcache


    【解决方案1】:
    hibernateTemplate.getSessionFactory().evictQueries("query.ContactInfoList");
    

    将清除该缓存区域。不能手动刷新缓存的查询数据;一旦查询再次运行,缓存区域将被重新填充(如果启用)。

    【讨论】:

    • 在 hiberanteTemplate.saveOrUpdate(contactLIst); 之后调用它hibernateTemplate.flush(); hibernateTempalte.getSessionFactory().evictQueries("query.ContactInfoLIst"); ?对吗?
    • 如果您明确调用flush() 来同步并发会话之间的状态,那么是的,您应该在flush() 之后立即驱逐。不过,这似乎是一个相当不寻常的场景(另外,您还必须处理一级缓存)。通常应避免手动调用flush();会话将在提交时刷新 - 在这种情况下,您可以在此之前驱逐查询。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 2022-08-20
    • 1970-01-01
    相关资源
    最近更新 更多