Skip to main content

Web Caching

Each virtual user (VU) maintains its own web cache as per the HTTP 1.1 specification.

Caching Behavior

When a script initiates a web request the caching behavior is as follows:

  • If the requested URL is in the VU's cache then:
    • If it is "fresh" (essentially not expired), set the cached page to be the current page and return immediately (no data is sent to the server).
    • If it is not fresh, then add If-None-Match and If-Modified-Since headers to the request. The request then becomes a conditional GET request (i.e., the server returns 304 Not Modified, rather than 200 OK if the resource has not been altered). If the response is a 304 Not Modified, merge the returned data with the cached data to form a full response.
  • If the URL is not in the cache, then add it.

Stored Content

By default, only the page content of certain mime types is both cached and stored. The default list is:

  • application
  • message
  • model
  • multipart
  • text

Thus any resource with a Content-Type header that starts with any of these words is cached and stored. So, content for text/html, text/xml, etc. is all stored when text is in the list of cached content types. This original content is then available to the virtual user. This list can be amended using the API, see cacheContentTypeDirectory().

For some content types it does not make sense to store the actual content. For example, "image" URLs are cached but their content is not stored. In most cases, a virtual user is not interested in the content of an image.

Pre-populating the Virtual User's Cache

A VU's Web cache can be pre-populated using the API, specifically the class CacheEntry.