Programmatically invalidating cached pages

Posted by / 07-Aug-2017 09:47

Programmatically invalidating cached pages

Note: In this example, the page will not be cached on the server.You can also generate the same headers programmatically, either from code-behind or from an Http Module.

Files that the browser retrieves from the server should be stored in the browser’s cache as long as possible to help minimize server round-trips.

Unfortunately, you can’t disable browser caching declaratively with the Output Cache directive. Here’s an example (see dyn-disable.aspx): The runtime includes the Pragma and Expires headers even though they aren’t needed in HTTP 1.1 and are therefore redundant in most cases.

You can eliminate the Expires header as follows (see dyn-disable2.aspx): The Expires: -1 header is supposed to prevent the page from being placed on the browser’s history list so that you can’t use the browser’s Back button to navigate to it again.

Every object stored in the browser cache includes an expiration time, beyond which the browser considers the content stale or invalid.

You can manage those expiration times with the Cache-Control: max-age HTTP header.

programmatically invalidating cached pages-77programmatically invalidating cached pages-44programmatically invalidating cached pages-43

Here’s what a conditional HTTP request looks like: GET /HTTP/1.1 Accept: */* Accept-Language: en-us UA-CPU: x86 Accept-Encoding: gzip, deflate If-Modified-Since: Sat, GMT If-None-Match: "80fc52fa8bb2c81:0" User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; . Even though the responses to conditional GETs are short, the round-trips alone can have a big effect on performance.

One thought on “programmatically invalidating cached pages”