Three things I'll do for a web application in in this instance.
1. Turn off the shared cache
2. Or Invalidate any objects I want to be refetched
3. Or Use thread local data context that will only exist during the
lifetime of my web request see an example below...
The trick with thread local is to make sure the thread gets cleaned
up. To do that I use a filter
/**
*..uthor Joshua T. Pyle
*..ersion Sep 20, 2005
*/
public class CayenneFilter implements Filter {
private static Log _log = LogFactory
.getLog("com.cool.something");
/**
*
*/
public CayenneFilter() {
super();
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
DataContext context = null;
try {
context = DataContext.getThreadDataContext();
} catch (IllegalStateException e) {
if (_log.isDebugEnabled()) {
_log.debug("", e);
}
// Bind the DataContext
context = DataContext.createDataContext();
DataContext.bindThreadDataContext(context);
}
chain.doFilter(request, response);
// Clean up the context
DataContext.bindThreadDataContext(null);
_log.info(this.getClass().getName() + " doFilter finished!");
}
public void destroy() {
// Nothing to do here
}
}
Then I can get the context any time I need...
public DataContext getDataContext() {
return DataContext.getThreadDataContext();
}
This filter based threadlocal approach is proving to be very handy.
The big issue is that the filter cleans up the thread.
-- Joshua T. Pyle Go has always existed.On 12/6/05, Jürgen Saar <jsaa..eb.de> wrote: > Caching is really a problem if there are > non-cayenne actions on the database. > > We are actually looking for alternatives to cayenne > because the trouble about caching > has become 'missing-critical'. > For our customer there is no acceptance for > seeing 'old' data in an actual requests. > > cayenne-use..bjectstyle.org schrieb am 06.12.05 21:50:51: > > > > Hi, > > > > I am refreshing an object I have loaded to update it if the DB has > > changed it while I am looking at it. I noticed that > > DataObjectUtils.objectForPK() is caching and I would like it not to, or > > find another way to get the object by id using a query. Any ideas? > > > > Thanks, > > Joseph > > > __________________________________________________________________________ > Erweitern Sie FreeMail zu einem noch leistungsstarkeren E-Mail-Postfach! > Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131 > >
This archive was generated by hypermail 2.0.0 : Wed Dec 07 2005 - 02:29:56 EST