ASP.NET Caching - Programatically Invalidating Server Cache...confusion on example -


i'm reading how programmatically invalidate cached pages on server in asp.net, , book ("mcts self-paced traing kit (exam 70-515)") says:

to directly control whether cached version of page used or whether page dynamically generated, response validatecacheoutput event , set valid value httpvalidationstatus attribute.

the code segments following:

public static void validatecacheoutput(httpcontext context, object data,         ref httpvalidationstatus status) {     if (context.request.querystring["status"] != null)     {         string pagestatus = context.request.querystring["status"];          if (pagestatus == "invalid")             status = httpvalidationstatus.invalid;         else if (pagestatus == "ignore")             status = httpvalidationstatus.ignorethisrequest;         else             status = httpvalidationstatus.valid;     }     else         status = httpvalidationstatus.valid; }  protected void page_load(object sender, eventargs e) {     response.cache.addvalidationcallback(         new httpcachevalidatehandler(validatecacheoutput),         null); } 

could please explain me code doing? also, main question have thought cached pages returned server, code below indicates page life-cycle being invoked (page_load event); i'm confused because page life-cycle isn't invoked if cached page returned, how code in page_load event fire?

note: here's same example book has

i came across question. bad every blog post , article find subject dutifully replicates msdn example without explaining how works.

i don't have definite answer think works because page life cycle invoked @ least once. namely when page requested first time , isn't cached yet. during first request page_load called , httpcachevalidatehandler registered cache object. during subsequent request page, cache object able call validatecacheoutput() method. , because method static page life-cycle doesn't have invoked.

i hope knows more can comment on in opinion implies following:

  1. in given example httpcachevalidatehandler doesn't need static method of page because doesn't use properties of page object. can static method on other object like.
  2. the validatecacheoutput() method called every page request, not page (ab)used call response.cache.addvalidationcallback(). maybe i'm missing obvious don't see how cache "knows" httpcachevalidatehandler belongs page.

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -