cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Schellink <>
Subject Re: Consolidate query and object cache
Date Sat, 10 Jul 2010 04:41:20 GMT
On 10/06/2010 16:25, Andrus Adamchik wrote:
> I am still unsure how to reconcile object and query cache at this point.
> My current direction with that is to place both object and query cache
> under the same cache storage and management mechanism. But I can't see
> how we can do automatic invalidation of the right query cache groups
> efficiently, as any given object change may result in object removal
> from some lists (when its properties no longer match list fetch
> conditions) or addition to some others, etc., etc. In fact cache groups
> mechanism was the answer to the inability to predict how an arbitrary
> object change affects the cache.
> If there are better ideas, I'll be happy to hear them.

I had some time reading up[1] on the approach Hibernate takes to caching. In short Hibernate
automatic query cache invalidation BUT according to the article[1] it is not as effective
as one
might expect and can have an inverse effect, making the application slower. Please note that
I am
simply passing on this information, I haven't verified this myself.

Like Cayenne, Hibernate has both an Object and Query cache (there is also a Collection cache
cache relationships). It also has a Timestamp cache that is used to automatically invalidate
Query cache. I'll quote the relevant part from the article:

"The timestamp cache keeps track of the last update timestamp for each table (this timestamp
updated for any table modification). If query caching is on, there is exactly one timestamp
and it is utilized by all query cache instances. Any time the query cache is checked for a
the timestamp cache is checked for all tables in the query. If the timestamp of the last update
on a
table is greater than the time the query results were cached, then the entry is removed and
lookup is a miss."

The problem with the Hibernate approach of 'automatic Query Cache invalidation' is that every
the Timestamp cache is updated for a table, queries over that table must be refetched. This
can lead
to many cache misses. The other problem (and reason why Hibernate Query Cache can have an
effect) is that the Timestamp cache can become a new bottleneck for the application.

Quoting the article again:

"This cache has a single coarse lock that is locked for all inserts/updates/deletes to update
timestamp of a table and also for every lookup that occurs through the query cache. Under
load, this
lock can easily become a bottleneck."

In summary: Cayenne's approach of Cache Groups with manual invalidation seems more efficient
useful compared to Hibernate.

Kind regards



View raw message