Nov 17, 2014 09:55 AM|Rion Williams|LINK
As I am developing asp.net web will be deployed on internet , I stored data table in session variable, I want to inquire which is best way of storing session variable, in database or in memory.
You may seriously want to reconsider this as the Session can be a bit of a slippery slope and should generally be avoided for any types of persistent storage (this is especially true of systems with a large number of users).
Some users believe the Session can be great for performance and generally users will experience this extremely fast speed when accessing values from it. This is because your actual data is going to be stored in memory for each user within your application
so when it is accessed, there isn't really any request that is going to be made to pull it. This creates a huge bottleneck in terms of resources for your application and can really come back to bite you if you have a large number of users or data :
(Number of Users) * (Size of Session) < (Server Memory / Resources)
If this value is exceeded, you could encounter an OutOfMemoryException and your application / web server would likely be restarted (clearing out the Session). This is just one of the many reasons that the Session isn't terribly "reliable" if you
need any sort of data persistence. Any number of things could cause the Session values to be wiped, which may or may not be in the middle of someone attempting to fetch them.
If you really need to store values or pass them around your applications, there are quite a few options out there that won't hamper your actual server down :
As you can see, there are quite a few alternatives to the Session, and I would recommend looking into each of these as they will allow you to built a much more tolerant and scalable solution.