2 replies
by gmp
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.
Trending Web Development posts
Sort by Trending