Alex Rivera | Logout

Advantages of Cache vs Session

Asked 2009-01-09T16:06:11.837
76

What is the difference between storing a datatable in Session vs Cache? What are the advantages and disadvantages?

So, if it is a simple search page which returns result in a datatable and binds it to a gridview. If user 'a' searches and user 'b' searches, is it better to store it in Session since each user would most likely have different results or can I still store each of their searches in Cache or does that not make sense since there is only one cache. I guess basically what I am trying to say is that would the Cache be overwritten.

Edit
Report

2 Answers

6

Cache is in the Application scope with the purpose of reducing the number of times a piece of data is obtained. Session is in a user's session scope with the purpose of giving a particular user state.

answered 2009-01-09T16:10:53.560
5

Session is per user, Cache is for the application.

Items in Cache can and will be removed automatically based upon expiration times (sliding or fixed) and memory constraints of the IIS worker process.

So basically items in Cache are never guaranteed to exist but Session will stay there until the session ends.

Storing items on a per-user basis (via Session or a creative use of Cache) can lead to a lot of memory usage and should be considered carefully.

On top of all of this, if IIS resets the worker process, you can lose your Cache and Session.

answered 2009-01-09T16:12:45.133

Your Answer