cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <>
Subject Re: cayenne.datacontext - session attribute- question
Date Sat, 23 May 2009 16:37:03 GMT
It sounds like you are using the Cayenne Servlet Filter:

This filter creates (or reattaches) a DataContext in (or from) the
user's session and attaches it to the current request thread.  This is
a convenience for applications that are heavily session-based.  A
DataContext itself is pretty lightweight, but it accumulates
CayenneDataObjects (database records) over time if you don't empty it
out.  You may want to look at the invalidateObjects() or
unregisterObjects() methods on the DataContext class:

Is it normal?  Yes.  Is it scalable?  A harder question to answer, but
you might have to be more careful with the way you access the database
and track objects.  Will it create problems with hundreds of sessions?
 Again, a harder question to answer.  You can certainly use a
session-based DataContext, but you might need to be more strategic in
managing it and the memory footprint.  Maybe you don't need a
session-based one?  Or maybe you don't need to keep as much stuff in
the session-based one?  If you only need to track objects during the
request, you could create a new DataContext and use it only during the
request and then it (and the database records it loads) won't be
stored in the session and will be garbage collected at the end of the
request.  You might also need to reset the session one to be an empty
one.  Essentially you'd create a new DataContext and replace the old
and potentially bloated one with the empty one.  Look at:


To see how Cayenne stores the DataContext in the session and the key
it uses for the session.


On Sat, May 23, 2009 at 11:32 AM, Devyandu <> wrote:
> Hi,
> I am using cayenne 2.04 with tomcat 5.5.
> Recently I started using a software called lambda probe, which is a tomcat
> analysis tool.
> I see that all my user sessions have an attribute called cayenne.datacontext,
> which has object of size (between 700K and 1MB) and type
> org.apache.cayenne.access.DataContext.
> This seems to be something that Cayenne creates and manages because I do not
> create this session attribute.
> 1. Is this normal?
> 2. Is this scalable?
> 3. Will it create problems if I have hundreds of sessions ?
> 4. In my struts actions/jsp, I get the context like this - DataContext
> context = DataContext.getThreadDataContext();. Is this OK?
> Thanks,
> Devyandu

View raw message