Hello.
+1 (move to cayenne and make it default behaviour)
This is a realy good idea. It should improve situations with a
context bound to a session as well. We need to have a pretty long
session timeout so this improvement should be significant.
I see that you have created a pluggable QueryCache. As discussed
before we should also create a DataRowStore equivalent with a
pluggable caching solution. I think you mentioned that this store
should cache DataObjects instead of DataRows, so I do not know where
to start :)
- Tore.
On Nov 14, 2006, at 16:02, Andrus Adamchik wrote:
As we all know, DataContext doesn't clean up unused registered
objects on an assumption that the entire DataContext has a finite
lifespan and will be garbage-collected eventually.
In my session-less web application I am using an app-scoped read-
only DC shared by all requests. Sure enough it leaks memory, given
a big enough database. In the past we solved this problem by
periodically replacing a shared instance of DC with a new one.
Since this approach intrerfered with the caching mechanism and
generally seemed dirty, the other day I implemented a self-cleaning
ObjectStore based on commons-collections ReferenceMap:
class LeakFreeObjectStore extends ObjectStore {
public LeakFreeObjectStore(DataRowStore dataRowCache) {
super(dataRowCache);
objectMap = new ReferenceMap(AbstractReferenceMap.HARD,
AbstractReferenceMap.WEAK);
}
}
Note that I couldn't use LRUMap, as we can't unregister objects
that are referenced by other application objects, so instead I used
weak references to cleanup otherwise unreferenced instances. Been
watching this in production for a day and it works perfectly.
Now the question is whether we want this behavior as a default (or
as an option) for the DataContext? In other words should I move
this fix to Cayenne? (I will have to modify it to create hard
references to the dirty objects as we can't deallocate those even
if they are not referenced in the app).
I'd say yes, but I was wondering if premature garbage collection of
registered objects is bad for any reason? Thoughts?
Andrus