you can just do Session["key"] = entity the catch is this:
1. if you use lazy loading you should attach the object to the NH session for every request (although for a user entity you'll probably load everything on session start unless its really alot of stuff) - because with session per request the NH session gets re-created on every request. use nhSession.Lock(user, LockMode.None) to attach it and then lazy loading is enabled. 2. if your user entity is updated by another Web-Session (like another user, or the same user from a different browser window) then your user entity will become stale. if you're ok with it being stale untill the end of the web-session then its fine, if not, you can put it in System.Web.Cache with a timeout policy, then when the timeouts ends, you'll re-fetch the user so it can only be stale for that timeout (can be 5 mins or so). On Fri, Apr 9, 2010 at 8:08 PM, Quintin Par <[email protected]> wrote: > Nadav, > > How do I store a persistent object in a session or web cache? > > > > On Fri, Apr 9, 2010 at 8:09 PM, nadav s <[email protected]> wrote: > >> if your okay with sticky session, something like the the current user >> could be saved in the in-proccess Session or System.Web.Cache >> >> IMO using the second level cache is great when you only need an object >> temporrarily, but the current user entity will surely be needed until the >> user's (web) session will die. >> >> On Fri, Apr 9, 2010 at 5:22 PM, Quintin Par <[email protected]> wrote: >> >>> The medium trust app I run is on godaddy with Mysql access (they might >>> have added additional perms) >>> >>> I have made all the association eager fetched and it works fine. >>> >>> Will the 2nd level or any other NH cache work in this scenario? >>> >>> >>> >>> On Fri, Apr 9, 2010 at 7:38 PM, John Davidson <[email protected]>wrote: >>> >>>> Medium trust applications do not normally have database access, unless >>>> that is an added modification to your trust implementation. Only SQL Server >>>> is supported in medium trust without policy modifications. Other databases >>>> require custom policy changes. >>>> http://msdn.microsoft.com/en-us/library/ms998341.aspx discusses the >>>> modifications required. >>>> >>>> http://nhforge.org/wikis/howtonh/run-in-medium-trust.aspx is a link to >>>> info about using NHibernate in a medium trust environment. The biggest >>>> change is the loss of lazy loading of associations, so you need to ensure >>>> your object model takes that limitation into account. Others may provide >>>> more detail if any of the NHibernate 2nd-level cache providers work in >>>> medium trust as that is not covered. >>>> >>>> Your options are 2nd-level cache from NHibernate (which probably >>>> requires custom policy for serialization of objects), ASP.NET caching >>>> (which again may require custom policy for serialization) or ASP.Net >>>> Session >>>> variables >>>> >>>> John Davidson >>>> >>>> On Fri, Apr 9, 2010 at 8:56 AM, Quintin Par <[email protected]>wrote: >>>> >>>>> Oskarm >>>>> Are these caching startegies available for medium trust applications? >>>>> -Quintin >>>>> >>>>> On Fri, Apr 9, 2010 at 6:09 PM, Oskar Berggren < >>>>> [email protected]> wrote: >>>>> >>>>>> Note that Get() or Load() doesn't matter for the case you describe. >>>>>> Get() will also return an already loaded object from the ISessions >>>>>> cache, if there is one. >>>>>> >>>>>> /Oskar >>>>>> >>>>>> >>>>>> 2010/4/9 Quintin Par <[email protected]>: >>>>>> > Hi, >>>>>> > >>>>>> > In my web application the master pagedoes authentication and loads >>>>>> up the >>>>>> > user entity using a Get. >>>>>> > >>>>>> > After this whenever the user object is needed by the usercontrols or >>>>>> any >>>>>> > other class I do a Load. >>>>>> > >>>>>> > Normally nhibernate is supposed to load the object from cache or >>>>>> return the >>>>>> > persistent loaded object whenever Load of called. But this is not >>>>>> the >>>>>> > behavior shown by my web application. NHprof always shows the sql >>>>>> whenever >>>>>> > Load is called. How do I verify the correct behavior of Load? >>>>>> > >>>>>> > -Quintin >>>>>> > >>>>>> > P.S. Cross posted at stackoverflow 4 days ago >>>>>> > >>>>>> > -- >>>>>> > You received this message because you are subscribed to the Google >>>>>> Groups >>>>>> > "nhusers" group. >>>>>> > To post to this group, send email to [email protected]. >>>>>> > To unsubscribe from this group, send email to >>>>>> > [email protected]<nhusers%[email protected]> >>>>>> . >>>>>> > For more options, visit this group at >>>>>> > http://groups.google.com/group/nhusers?hl=en. >>>>>> > >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "nhusers" group. >>>>>> To post to this group, send email to [email protected]. >>>>>> To unsubscribe from this group, send email to >>>>>> [email protected]<nhusers%[email protected]> >>>>>> . >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/nhusers?hl=en. >>>>>> >>>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "nhusers" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]<nhusers%[email protected]> >>>>> . >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/nhusers?hl=en. >>>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "nhusers" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]<nhusers%[email protected]> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/nhusers?hl=en. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "nhusers" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]<nhusers%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/nhusers?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<nhusers%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
