Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I also came across this question. It is too bad that almost every blog post and article I find about this subject dutifully replicates the <a href="http://msdn.microsoft.com/en-us/library/a5e5hdyz.aspx" rel="nofollow">MSDN example</a> without really explaining how it works.</p> <p>I don't have a definite answer but I think this works because the page life cycle is invoked at least once. Namely when the page is requested for the first time and thus isn't cached yet. During that first request the Page_Load is called and the <code>HttpCacheValidateHandler</code> is registered with the Cache object. During all subsequent request for that page, the Cache object is able to call your <code>ValidateCacheOutput()</code> method. And because this method is <code>static</code> the page life-cycle doesn't have to be invoked.</p> <p>I hope that someone who knows more about this can comment on it but in my opinion this also implies the following:</p> <ol> <li>In the given example the <code>HttpCacheValidateHandler</code> doesn't need to be a static method of the page because it doesn't use any properties of the <code>Page</code> object. It can be a static method on any other object you like.</li> <li>The <code>ValidateCacheOutput()</code> method will probably be called for every page request, not just for the page which is (ab)used to call <code>Response.Cache.AddValidationCallback()</code>. Maybe i'm missing something obvious but I don't see how the Cache "knows" which <code>HttpCacheValidateHandler</code> belongs to which page.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload