Caching Strategies

  1. “Time-based conditional request” explained here – https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers#conditional-requests

 

Basics:

“Conditional requests are those where the browser can ask the server if it has an updated copy of the resource. The browser will send some information about the cached resource it holds and the server will determine whether updated content should be returned or the browser’s copy is the most recent. In the case of the latter an HTTP status of 304 (not modified) is returned.

Though conditional requests do invoke a call across the network, unmodified resources result in an empty response body – saving the cost of transferring the resource back to the end client. The backend service is also often able to very quickly determine a resource’s last modified date without accessing the resource which itself saves non-trivial processing time.

Time-based

A time-based conditional request ensures that only if the requested resource has changed since the browser’s copy was cached will the contents be transferred. If the cached copy is the most up-to-date then the server returns the 304 response code.

To enable conditional requests the application specifies the last modified time of a resource via theLast-Modified response header.

Cache-Control:public, max-age=31536000Last-Modified: Mon, 03 Jan 2011 17:45:57 GMT

The next time the browser requests this resource it will only ask for the contents of the resource if they’re unchanged since this date using the If-Modified-Since request header

If-Modified-Since: Mon, 03 Jan 2011 17:45:57 GMT

If the resource hasn’t changed since Mon, 03 Jan 2011 17:45:57 GMT the server will return with an empty body with the 304 response code.

 

  1. The Cache control headers

 

Browser sends request with following caching headers –

 

If-Modified-Since: Tue, 26 Jul 2016 09:55:44 GMT

If-None-Match: “3b278fe023e7d11:0”

 

 

The response from udjsapi contains following caching related headers. The response is either 200/304 depending on whether the browser copy is the latest or not.

 

Cache-Control: private

Last-Modified: Tue, 26 Jul 2016 10:06:16 GMT

ETag: “a9a0295925e7d11:0”

 

 

  1. IIS settings to enable caching

 

Update the web.config file like so:

 

<?xml version=”1.0″ encoding=”UTF-8″?>

<configuration>

<system.webServer>

<staticContent>

<clientCache cacheControlMode=”NoControl” cacheControlMaxAge=”1.00:00:00″ />

</staticContent>

<httpProtocol>

<customHeaders>

<add name=”Cache-Control” value=”private” />

</customHeaders>

</httpProtocol>

</system.webServer>

</configuration>