NCache 4.3 - Online Documentation

View State Caching

 
All ASP.NET applications have to deal with View State which is becoming a performance overhead. ViewState caching helps you cache View State on web servers and send a much smaller payload to the user's browser containing only a unique ID for this ViewState. As a result, your page performance improves and your ASP.NET application also scales much better.
 
Why Cache View State?
 
View State is an encrypted text string containing the state of web form controls and widgets and is sent to the user's browser to preserve the state across post-backs. For forms with lot of controls, DataGrid control, or some other complex controls, the View State can become quite large. Here are some reasons why you should consider caching the View State.
  • View State is large (tens of kb) on large forms & DataGrid.
  • Large View State slows down page download time.
  • Large View State slows down post-back request time.
  • Can cache View State on web servers & send only a token to user.
  • View State cache is distributed to all web servers in the farm.
 
How NCache Caches View State?
 
View State is included in the response of a web request as a hidden form field called __VIEWSTATE. On all page visits during the save view state stage, the Page class gathers the collective view state for all of the controls in its control hierarchy and serializes the state to a base-64 encoded string.
 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzg0MDMxMDA1D2QWAmYPZBYCZg9kFgQCAQ9kFgICBQ9kFgJmD2QWAgIBDxYCHhNQcm V2aW91c0....zgoNOvWxd4w==" />
 
Once NCache caches this View State, it replaces the "id" and "value" fields with its own data. Here is an example of that.
 
< input type = "hidden" name = "__NCPVIEWSTATE" id = "__NCPVIEWSTATE" value = "vs:cf8c8d3927ad4c1a84da7f891bb89185" />
< input type = "hidden" name = "__VIEWSTATE" id = "__VIEWSTATE" value = "" />
 
Notice, how it is preserved the original "__VIEWSTATE" hidden field so everything works as if there was no View State. But, it has inserted its own "__NCPVIEWSTATE" field that it will read when a post-back request comes from the user to the web server. NCache uses the "value" as the key to fetch the corresponding original View State from the in-memory cache and serves it to the ASP.NET page so it can populate the web form with data from the View State.
And, since the in-memory cache is distributed and synchronized across all web servers, even if the post-back request goes to a different web server in the farm than the original server where the View State was created, NCache is able to find the View State value in the cache.
 
Note: It is recommended not to disable viewstate caching during peak hours because it may corrupt the viewstate of already opened pages.
 
 
See Also
 

 
© Copyright  2014 Alachisoft. All rights reserved.