These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Reattatch object stored in cache to "new" session
PostPosted: Mon Jan 29, 2007 2:55 pm 
Newbie

Joined: Mon Jan 29, 2007 2:44 pm
Posts: 6
Please tell me the correct way to reattatch an object stored in System.Web.Caching.Cache to a "new" session object. I have tried several ways to do this and experienced problems for example when saving objects that is reattatched to session after getting it from System.Web.Caching.Cache.

It's a webapplication and i'm opening a new session for each request and closing it on request end.

I'm trying to build my own cache that is not implementing the NHibernate.Cache.ICache

I have tried to use NHibernate.Caches.SysCache but seems to delete all objects/lists of type(T) when saving one object of type(T), but maybe i'm wrong. If this is the case I'm not so happy about it ;-)

I'm using NHibernate-1.2.0.Beta3

/A


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 4:46 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
This is a bad idea in general, what you end up doing is re associating the object with more than a single session at a time - because you are using the same instance in multiply requests. This is obviously not thread safe.

NHibernate doesn't evict all objects of T from the cache for a single update, maybe you are thinking about the query cache?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 5:01 pm 
Newbie

Joined: Mon Jan 29, 2007 2:44 pm
Posts: 6
Yes, I was thinking about the querycache.

So, is this a good practice:

Get objects from cache when used for read-only purpose, ie. you as a developer has to decide to get objects in read-only mode or not. Read-only objects is stored in cache and loaded from cache and can not be updated in db.

In applicationcode that updates objects you have to load them from db (Session.Load) and perform the update and then remove assosiated objects in cache.

/A


Last edited by andr on Tue Jan 30, 2007 2:30 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 5:03 pm 
Newbie

Joined: Mon Jan 29, 2007 2:44 pm
Posts: 6
Ayende Rahien wrote:
This is a bad idea in general, what you end up doing is re associating the object with more than a single session at a time - because you are using the same instance in multiply requests. This is obviously not thread safe.

NHibernate doesn't evict all objects of T from the cache for a single update, maybe you are thinking about the query cache?


But you can always do a clone of the object stored in cache.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.