Variables in memory on server once session times out
I've created a web site that is used mainly to do reporting on multiple locations and e-mail reports and things like that. Since its dealing with a lot of information I've set it up so it grabs a bunch of information at one time then I go through it with linq and filter it however I need to. When someone actually clicks the logout button then the variables are released and cleaned up.
My questiion is what happens to those variables if t开发者_运维问答he user never actually clicks logout and either lets the session timeout or x's out of the web browser they are using?
If the variables aren't released how do people normally handle that?
Thanks, Mike
The way you've described it, it sounds like the best solution is to store the data in cache, so that you can reference it whenever you need to.
Here is a simple example of how to cache a DataSet object:
DataSet ds = RetrieveLotsOfData();
Cache["MyDataSet"] = ds;
Once the data is stored in cache, you can reference it anywhere like this:
DataSet ds = (DataSet)Cache["MyDataSet"];
See this article for an overview of cache management in ASP.NET:
http://www.codeproject.com/KB/web-cache/cachemanagementinaspnet.aspx
If your session times out (it will eventually) then your server will release it's reference to the Session
object which holds the reference to the object that you're storing in the SessionState
. When there's no reference left for an object it's automatically garbage collected when the garbage collector is run. By the way, if your user clicks logout
it doesn't mean the objects are cleared immediately but just that the objects are made available for garbage collection. This way you're not really sure when they will be collected but this allows the garbage collection process to only run if needed and do some extra cleaning when your application is not under heavy load.
精彩评论