How to find out if the content is coming from cache or original server

Lets say your debugging issue of why the new image that you just uploaded on your server is not getting reflected on a page and want to find if that image is coming from a proxy cache server somewhere in between.

The Http Protocol does not have any header that (Via header can be used by advanced proxies but i had never seen that) can tell you if the image is coming from cache somewhere instead of original server. You can use the Date header to figure out if the request is coming from the cache or actual server.

As per the Specification Date header represents the time when the response was generated by server. Now if Proxy is caching the response it will also cache the Date header value and when you try accessing that resource, cache will return you cached copy as well as value of Date header.

Ex. I tried going to www.yahoo.com on 14 th of July and these are the headers that i am getting



As you can see that the value of Date header is 12th of July, which means that the cache got response from server on 12 th of July and that response is cached. If you look at value of cache-control header it is set to max-age=315360000, which is 10 years. Value of Expires headers is 09 July 2020, which means the server is saying that the image is valid for next 10 years. So when proxy gets a request for the first time it will get the image and keep it in cache for other clients for next 10 years, it wont even check if the image is updated for next 10 years and keep returning Date header with value when it actually got the image from server.

No comments: