Discussion Locked

Datasets and sessions...

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Whilst developing with classic ASP I was always under the impression that the less you made use of session variables the better for scalability and performance reasons. I understand that entire db's aren't stored on the users machine as mentioned in the article but I have read a lot of .Netters suggesting storing whole datasets in session variables between page requests. Is this good practice?

2 replies

by pnschofield

For scalability reasons, it can be a bad idea to load lots of data into Session because the data remains in the server's memory until the session times out or until the object is explicitly removed. If you have a lot of users hit your site in a short period of time and you load up data into their Sessions, you can tie up a lot of memory.

You have several alternatives:

1. Requery the database each time you need the data. This is more expensive performance-wise, but it improves scalability. And you should have a beefy db server anyway.
2. Use the ASP.NET caching API found in the System.Web.Caching namespace. The Cache is similar to Session in that it stores data in memory. However, when your server starts to run low on memory, objects can be automatically released from the cache. You can even write code that will be called as an item is removed from the cache. If/when a user makes a request for data that has been removed from the cache, you can simply requery the database and insert the results back into the cache. Objects that are expensive to populate can be given a higher priority, so that they are removed from the cache last.

This discussion is closed to new replies.