Hello all i am new to Asp.Net could anyone tell me what is the difference between cache and session in real time.
3 Answers
Session: Session is used to store data,It is user specific. It can be accessible through out the site. Session has 4 modes:
- In Proc ( Data is stored in memory )
- State Service ( Data is stored in a service, the benefit is if your application restarts session still exits )
- Sql Server ( same benefit as state server has )
- In Proc ( without cookies ) a session_id is attached to URL. THis is used when user has disabled cookies.
Example:
Session["key"] = "value"; // You can store any object data type.
Cache: There are two types of cache in asp.net.
- Page Output Caching: You can cache the whole page by specifying the PageOutput direcitve at the top of the page.It store's the rendered page in the Cache. It is used when your page is accessed by thousands of users, so to increase the response time, we cache that page.
Application Caching: It allows to store any object in memory and automatically removed the object based on some limitations e.g time or some other dependencies . Example:
Cache["key"] = "value"; // it also supports any object data type.
Remember Cache and Session are different things.

- 6,113
- 2
- 26
- 36
A Session is available for a user till the application is alive and the session is not abandoned.
Well a cache can be made available for the enitre application level or user level
One major difference between both is that you items in cache can expire after given time to cahce well as items in session will stay till session expires

- 11,077
- 3
- 28
- 43
- session is per user
2.if your server is low memory asp.net will remove cache to free memory
3.we use cache to share same value with all users

- 135
- 5