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

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 MSDN example without really explaining how it works 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 HttpCacheValidateHandler is registered with the Cache object. During all subsequent request for that page, the Cache object is able to call your ValidateCacheOutput() method. And because this method is static the page life-cycle doesn't have to be invoked I hope that someone who knows more about this can comment on it but in my opinion this also implies the following: In the given example the HttpCacheValidateHandler doesn't need to be a static method of the page because it doesn't use any properties of the Page object.It can be a static method on any other object you like The ValidateCacheOutput() method will probably be called for every page request, not just for the page which is (ab)used to call Response.Cache.

AddValidationCallback() Maybe i'm missing something obvious but I don't see how the Cache "knows" which HttpCacheValidateHandler belongs to which page.

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 MSDN example without really explaining how it works. 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 HttpCacheValidateHandler is registered with the Cache object. During all subsequent request for that page, the Cache object is able to call your ValidateCacheOutput() method.

And because this method is static the page life-cycle doesn't have to be invoked. I hope that someone who knows more about this can comment on it but in my opinion this also implies the following: In the given example the HttpCacheValidateHandler doesn't need to be a static method of the page because it doesn't use any properties of the Page object. It can be a static method on any other object you like.

The ValidateCacheOutput() method will probably be called for every page request, not just for the page which is (ab)used to call Response.Cache. AddValidationCallback(). Maybe i'm missing something obvious but I don't see how the Cache "knows" which HttpCacheValidateHandler belongs to which page.

You are right in that typically cached pages are just returned frm the server but this changes when you use AddValidationCallback. In this case, ASP. NET will call this method to determine whether to returned a cached copy or not.

This method should therefore be very light or you will negate the effect of caching. The code you have listed just checks the querystring for a Status variable and uses the value of this to determine whether to either (1) pull the page from the cache, (2) clear the cached page, re-render it and cache it or (3) just ignore the cache and re-render the page. See msdn.microsoft.com/en-us/library/system.... for the status options.

It is too bad that almost every blog post and article I find about this subject dutifully replicates the MSDN example without really explaining how it works. 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 HttpCacheValidateHandler is registered with the Cache object. During all subsequent request for that page, the Cache object is able to call your ValidateCacheOutput() method. And because this method is static the page life-cycle doesn't have to be invoked.

In the given example the HttpCacheValidateHandler doesn't need to be a static method of the page because it doesn't use any properties of the Page object. It can be a static method on any other object you like. The ValidateCacheOutput() method will probably be called for every page request, not just for the page which is (ab)used to call Response.Cache.

Maybe i'm missing something obvious but I don't see how the Cache "knows" which HttpCacheValidateHandler belongs to which page.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions