3

When using Hibernate and Ehcache as a second-level cache (2LC) implementation, is (or can) this cache used when doing COUNT operations with a WHERE clause?

In SQL terms the query I'm performing is SELECT COUNT(id) FROM table WHERE someColumn > 100. In some instances the value passed will be different each time, sometimes it will always be the same.

I'm assuming this is outside of the scope of 2LC, and instead would need to be managed 'manually' (cache the result of the query, and invalidate that cache whenever the underlying data change).

1 Answer 1

4

You are right, this is beyound what L2 cache offers. However query cache will do the trick.

Basically Hibernate will cache a mapping between named parameters ([100] tuple in your example) and a query result in a cache named org.hibernate.cache.StandardQueryCache. It will also invalidate the cache when any changes are made to table (more precisely: any table that is used in a query). The last modification time of each table is stored in org.hibernate.cache.UpdateTimestampsCache cache.

See also:

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.