hibernate query cache specify cache duration
below is how i do query cache
getHibernateTemplate().setCacheQueries(true);
List<IssSection> result = (List<IssSection>) getHibernateTemplate().findByCriteria(crit);
getHibernateTemplate().setCacheQueries(false);
may i know how to specify duration of maximu开发者_开发技巧m time to cache this method? let say i want to clear cache after 5 mins expirated
Hibernate does not provide an interface for controlling specifics of the cache such as you request.
Instead, you have to choose a cache implementation that provides that functionality, and configure it appropriately.
E.g. you can use EhCache and configure it like so:
<cache
name="com.somecompany.someproject.domain.Country"
maxElementsInMemory="10000"
eternal="false"
**timeToIdleSeconds="300"**
**timeToLiveSeconds="600"**
overflowToDisk="true"
/>
The two highlighted attributes above illustrate how you may configure the duration of cached time for the cached elements.
May I know how to specify duration of maximum time to cache this method?
You would have to choose a L2 cache provider supporting expiration (EHCache, OSCache, JCS) and to configure the cache region for this particular request.
精彩评论