views:

274

answers:

1
<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;
}

may i know how to clear/refresh cache for query.ContactInfoList when calling hibernatetemplate saveupdate

+3  A: 
hibernateTemplate.getSessionFactory().evictQueries("query.ContactInfoList");

will clear that cache region. You can't manually refresh cached query data; cache region will be re-populated (if enabled) once the query runs again.

ChssPly76
call this after hiberanteTemplate.saveOrUpdate(contactLIst); hibernateTemplate.flush(); hibernateTempalte.getSessionFactory().evictQueries("query.ContactInfoLIst"); ? correct?
cometta
If you're calling `flush()` explicitly to synchronize the state between concurrent sessions then yes, you should evict right after `flush()`. This seems like a rather unusual scenario, though (plus you'd have to deal with 1st level cache too). Normally, calling `flush()` manually should be avoided; session will be flushed on commit - in that scenario you can evict queries just prior to that.
ChssPly76