1

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 maximum time to cache this method? let say i want to clear cache after 5 mins expirated

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.