I'm trying to cache the results of a very repetitive query, and am running into problems using the new query cache of 2.1 rc1.
I've configured my second-level cache (I'm using OSCache) so that it is unlimited for the time being, I've put the <cache... tag into my XML descriptor for the class, and I've made the class immutable.
I've turned on the query cache, set the query to setCacheable(true), and then I run the query. The first time I run the query, it correctly caches the results. However, the second time and any further times I run the query, it outputs the following, invalidates the cache and repopulates it.
Code:
10:01:51,728 DEBUG QueryCache:61 - checking cached query results in region: net.sf.hibernate.cache.QueryCache
10:01:51,728 DEBUG QueryCache:70 - cached query results were not up to date
For each entity, I get the following after running the query, so I'm assuming the second-level cache is working correctly:
Code:
10:01:51,938 DEBUG SessionImpl:2135 - adding entity to second-level cache
I'm using Hibernate for all access to my data - I was under the assumption that the query cache worked on the basis that it checked to see whether any updates or deletes had happened on the data using the UpdateTimestampsCache. Considering that I'm running the queries back to back, just as a simple test and no other access is going on, am I doing something fundamentally wrong?