Invalidating query cache
Caching introduces overhead in the area of transactional processing.
For example, if you cache results of a query against an object, Hibernate needs to keep track of whether any changes have been committed against the object, and invalidate the cache accordingly.
By default Cache Machine does not invalidate queries when a new object is created, because it can be expensive to maintain a flush list of all the queries associated with a given table and cause significant disruption on high-volume sites when the queries for a particular model are invalidated at once.
If you have queries that run over and over, with the same parameters, query caching provides performance gains.Cache Machine would have to do a full select to figure out the object keys, which is probably much more data than you want to pull.I recommend a short cache timeout; long enough to avoid repetitive queries, but short enough that stale counts won’t be a big deal.If it’s there, we return the cached result set and everyone is happy.If the query isn’t in the cache, the normal codepath to run a database query is executed.
Search for invalidating query cache:
The query keys themselves are based on as many uniquely identifying aspects of a query that we could think of.