04 July 2011

Caching in IIS, TMG and the browser - How it all fits together Part I - Browser cache

Caching as a mechanism for speeding things up has been around for a long time now.  It is unfortunately a concept that is not well understood.  The reason for this is probably because there are so many variables.

In this series of articles I will cover the fundamentals of caching at the three main locations.  Web Server, Proxy cache (TMG) and the local browser cache.

Client Browser Cache

When items are flagged as being valid for caching the items are stored locally on the client machine.  When the items are requested again, the items are retrieved from the local file system.

This has the advantage of reducing the TCP round trip as well as reducing the amount of data that needs to be downloaded.

When using an HTTP sniffer such as HTTP Watch or Fire Bug you can observer the result codes.  To find out more about the result codes check http://fixmyitsystem.com/2011/07/http-status-codes-quick-guide.html


First Visit
At first visit to a page you will return result 200 for all the items.  This indicates that the item was successfully downloaded.  Looking at the other column values you can see that the sent and receive indicate the size of them items


Cache allowed items will now be written into the local machine cache.  The setting for this is specified in the Internet Explorer  - Internet Options - Browsing History - Settings.  There are 4 options for updating the cache, they are:

  • Every time I visit the webpage
  • Every time I start Internet Explorer
  • Automatically (default)
  • Never


You can also specify the amount of disk space you want to allocate as well as the cache location.  It is important to note that this is a user specific cache. As in, even if another user logs onto the same machine the cache would not be available to them.


Repeat Visit
When visit the site for the again your cache will start being utilized.  You can see that items that are  allowed to be cached are returned form the local cache.  Looking at the sent and received columns you can also see that no data was sent or retrieved for this.  You can get this behavior by pressing enter in the address bar or clicking on a link to the page.



Refreshing
When you refresh a page using F5 or clicking the refresh icon, you force internet explorer to request a new version of the files.  You would then expect that all the files be retrieved from the server as it did in the first visit, but it does not.  Instead you get all cache allowed items returned with a code 304.  This indicates that the item has not been modified since the last visit.  This has the advantage that only a small "version check" is sent and retrieved form the web server.


Clearing the cache
To clear all the local cache you need to delete all the Temporary Internet files.  From Internet Explorer - Internet Options - Browsing History - Delete - Check Temporary Internet Files.  Reloading the web page will the return all items from the web server as it did on the first visit.

This concludes the section cover cache on the user's local machine.  This is however not the end of the caching story.  There are additional place where the web content can be cached.  All of which are transparent to the user.   If the item is retrieved form a proxy cache or a web server cache, it still is retrieved externally.

No comments:

Post a Comment