hibernatetemplate清除ehcache?

时间:2009-12-01 07:19:55

标签: java hibernate spring ehcache

<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时清除/刷新缓存 query.ContactInfoList saveupdate

1 个答案:

答案 0 :(得分:3)

hibernateTemplate.getSessionFactory().evictQueries("query.ContactInfoList");

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

相关问题