Alachisoft NCache 4.1 - 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 V2aW91c0NvbnRyb2xNb2RlCymIAU1pY3Jvc29mdC5TaGFyZVBvaW50LldlYkNvbnRyb2xzLlNQQ29udHJ vbE1vZGUsIE1pY3Jvc29mdC5TaGFyZVBvaW50LCBWZXJzaW9uPTEyLjAuMC4wLCBDdWx0dXJlPW5ldXRy YWwsIFB1YmxpY0tleVRva2VuPTcxZTliY2UxMTFlOTQyOWMBZAIDD2QWDgIBD2QWBgUmZ19lMzI3YTQwM F83ZDA1XzRlMjJfODM3Y19kOWQ1ZTc2YmY1M2IPD2RkZAUmZ18yNDQ3NmI4YV8xY2FlXzRmYTVfOTkxNl 8xYjIyZGYwNmMzZTQPZBYCZg8PZBYCHgVjbGFzcwUbbXMtc2J0YWJsZWFsdCBtcy1zYnRhYmxlLWV4ZAU mZ181NmIxMzIzMV9kYjllXzRlYTZfOTc5ZF9iYWZlNDk3MDkyOWUPZBYCAgEPZBYCAgEPPCsADQ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RkZAIlD2QWAgIHDw8WA h8GaGQWAgIFD2QWAgIBDzwrAAkBAA8WAh4NTmV2ZXJFeHBhbmRlZGdkZAIvD2QWAgIED2QWDgIDDxYCHw ALKwQBZAIFDxYCHwALKwQBZAIHD2QWAmYPDxYCHwZoZGQCCQ9kFgJmDw8WAh8GaGRkAgsPZBYCZg8PFgI fBmhkZAIND2QWAmYPDxYCHwZoZGQCDw9kFgJmDw8WAh8GaGRkGAIFOWN0bDAwJG0kZ181NmIxMzIzMV9k YjllXzRlYTZfOTc5ZF9iYWZlNDk3MDkyOWUkY3RsMDEkZ3JpZA8UKwADPCsACgEIZgL/////DwL/////D 2QFRWN0bDAwJFBsYWNlSG9sZGVyVG9wTmF2QmFyJFBsYWNlSG9sZGVySG9yaXpvbnRhbE5hdiRUb3BOYX ZpZ2F0aW9uTWVudQ8PZAUKQWxsIGluIE9uZWQiMPVaPthHdSA3rH8zgoNOvWxd4w==" />
 
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 © 2005-2012 Alachisoft. All rights reserved.