Hi Davide,
1) Unless your application is read-mostly, and it doesn't sound like
it is, you'll want separate DataContexts per user to track their
individual changes in distinct DataContexts. Otherwise the changes
will get co-mingled and chaos likely will ensue.
2) You should be fine, but you can always fine-tune later if required
by kicking objects out of the DataContext yourself where it makes
sense. I'd optimize this later, though, as it may not be needed.
mrg
On May 22, 2010, at 5:03 AM, "mr.abanjo" <mr.abanj..mail.com> wrote:
> Hi,
> I'm developing a simple web application that store in a table an user
> preference.
> When a new user comes, i save a new record to a database using
> datacontext:
> *
> *
> *datacontext.registerNewObject<http://cayenne.apache.org/doc30/api/org/apache/cayenne/access/DataContext.html#registerNewObject(java.lang.Object)
> >
> *(Object<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html?is-external=true
> >
> myobject);
> *datacontext.**commitChanges<http://cayenne.apache.org/doc30/api/org/apache/cayenne/access/DataContext.html#commitChanges
> ()>
> *();
>
> Cayenne perform an insert and all works fine.
> I have 2 questions:
>
> 1) Reading the documentation the right way in a web application to
> create a
> datacontext is per session:
> http://cayenne.apache.org/doc30/obtaining-datacontext.html
> What happens if i treat it as a singleton? ( So i have one instance
> for all
> the users )
>
> 2) My web application has a high traffic, so i think that in a few
> time i've
> "registered" in datacontext thousands of record. This objects are
> correctly
> garbage collected or they stay in memory?
> Reading the documentation:
>
> Since Cayenne 3.0, by default DataContext uses weak references to
> store
> registered objects. So objects are allowed to be garbage collected
> by the VM
> if they are not referenced elsewhere in the application. "Elsewhere"
> usually
> means one of the following:
>
> - An object is directly or indirectly referenced by the
> application. [*NO
> reference to them by any object in my application]*
> - An object is a part of the cached query result stored by
> Cayenne. [*I
> never configured cayenne for cache.. so if i'm not wrong, the
> default is
> NO-CACHE]*
> - An object is "dirty" (i.e. new, modified or deleted). In this case
> Cayenne ensures that such object is retained at least until commit
> or
> rollback. [*I perform always a commit after registering a new
> object]*
>
> So... i think that the memory should be correctly freed.
>
> N.B. I'm using Cayenne 3.0!
>
> Thanks for help!
> Davide
This archive was generated by hypermail 2.0.0 : Sat May 22 2010 - 11:51:29 UTC