Differences between Cache, Session and ViewState

URL: http://www.progtalk.com/ViewArticle.aspx?ArticleID=62

  • memory.
  • allow you to store difficult and complex constructed data which will can be reused.
  • is available to be accessed from global/application level where one reference to memory is updated. Each request will use the same cache for different users.


  • a period of time that is shared between the web application and the user.
  • Each user that is using the web application has their own session.
  • The Session variables will be cleared by the application which can clear it, as well as through the timeout property in the web config file.
  • Session variables will use different session variables for each different user.


  • hidden data that is kept by ASP.NET pages.
  • track the changes to a web site during post backs.
  • All server controls contain a view state. [EnableViewState property - enable/disable if the control properties will be held in hidden fields.]
  • Having a large ViewState will cause a page to download slowly from the users side.- When a user clicks on a button and a post back occurs, all the view state information has to be posted back to the server which causes a slower request.
  • ViewState should be limited to what is needed.- Data can also be written into the ViewState. - The ViewState only persists for the life cycle of the page.
  • If the page redirects to another page, or even to itself, the ViewState will be reset.
  • ViewState should be used to hold small amonts of data, which will be only used on the current page