Re: Store Asyncresult to session with sessionState mode = "SQLServer"

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi!

but I opted for a considerably simpler option
that seems to work perfectly. I wanted to store the result in the
session so I could maintain separate asynchronous operations for each
logged in user.

Cache("result" + Session.SessionID) = ar

Ok. But be aware that:

* A new Session may get the same SessionID again (because when a Session
ends the cookie remains within the Browsers memory). So it is no bad idea to
clear the value from the cache within Session_Start

* Cache items may get removed from the Cache automaticly. There are memory -
limits for the cache. At least you should insert the objects with the
CacheItemPriority.NotRemovable.

I would still recommend that you use static Fields instead of the Cache to
avoid the unnessersary overhead of the Cache Object because you do not need
the things that the Cache Object offers you (like expiration, dependecies
and auto-remove), you just want to store a Object-Reference within memory.

You can use the SessionID as a key within the helper - property:

static class AsyncResultManager {

public static Dictionary<string, IAsyncResult> _dic = new ...();

public static IAsyncResult UserAsyncResult {
get{
return _dic[HttpContext.Current.Session.SessionID];
}

set{
_dic[HttpCOntext.Current.Session.SessionID] = value;
}

}

}



GP


.



Relevant Pages

  • Re: Session VS. Cache
    ... Session is user specific. ... You don't want to store your dataset there unless ... I'm pretty sure there's functionality built into the Cache object that lets ... > in the Cache if I have to worry about the system purging it. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ViewState, Application, Session....
    ... viewstate and as a part of Request pipeline the framework initializes the ... Session: Session is a storage area that is specific to one user. ... there are times when session provides a good way to store user specific ... Application or Cache: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Session VS. Cache
    ... When is it better to store a small amount of data (say a very small DataSet ... or a couple of short string variables) in the Session vs in the Cache ... in the Cache if I have to worry about the system purging it. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Caching and cookieless sessions
    ... The problem is that I have an adapted version which is supposed to store the FormsAuthenticationTicket in a cache. ... Any ideas how to get the Session object in this function or how to store something in the Application object with a timeout. ...
    (microsoft.public.dotnet.general)
  • Re: How best to use php5 objects between pages?
    ... > or cache storage (PHP-APC cache can provide this, ... 1.He can use APC cache instead of dealing shared memory by himself. ... session files or databases. ... Session files are relatively secure. ...
    (comp.lang.php)