Hi kbosselman,
don't worry I appreciate a good discussion ;-)
Quote:
turning the caching of the relationship off would also be inefficient as that would force a re-read of the relationship every time we accessed it
this is not true, there's first level cache too: until you detach your object graph from the session you are not going to repeat unnecessary data reads.
-- We're using a short transaction model so our objects are mostly detached and then reattached when necessary, so the first level cache only comes into play ligthly. The general use case would have the relationship being re-read repeatedly.
Quote:
there is no need to worry about reading and writing the objects to and from a second level cache
You don't have to, wen you enable it it's Hibernato who will put and get objects from the cache, no code changes.
-- While this is true, there is no coding involved, putting and getting things from the second level cache is not free. In my limited testing using ehcache, at times it took longer to retreive an object from the cache than it did from the db.
Quote:
If we go to a local cache we are still going to have to handle concurrency issues manually
You have to handle them anyway, at least handling optimistic locking; please remember your first level cache can't be turned off; also keeping objects a long time enlarges your probability of stale data, so reloading the objects often is a good thing: when it's unneeded the cache will tell you transparently, automatically, and you can change this policies from outside the code, even replacing your cache manager.
-- Since our problem space has very limited concurrency issues dealing with stale data is of less importance than limiting extra data acceses. In the general use case we can (safely) optimistically assume that the data we have in memory is not stale, so best performance is achieved if we can avoid unecessary re-reading of data from either the second-level cache or the db.
Quote:
So while implementing a second level cache may indeed solve my issue it would seem to be a heavyweight solution to what I see as a lightweight problem.
so I think we are actually speaking about the same solution in different words; what you are saying is that you want to keep the main object (I call that caching) and reload the collection, using some lightweight solution; eh-cache really is quite lightweight.
-- I can definitely see use cases where relying on the second level cache is the thing to do, I just don't see where it fits our specific model very well. If we were more concerned about concurrency/stale data than limiting data accesses and if we had more data being shared between threads using the second level cache would then be worth the cost. (Which may be small in terms of coding, but no matter how light weight eh-cache is it is certainly not free in terms of performance)
kind regards,