Chapter 8. Caching

The following pseudo-code shows how the cache refresh logic works:

if “Expires” and “Last-Modified” headers are missing then validate file.

else if Cache modification time + Maximum age < Current time then validate file.

else if “Last-Modified” header is present and “Expires” header is not present and Last-Modified time + Last-Modified time factor < Current time then validate file.

else if “Last-Modified” header is present and Last-Modified time + Minimum age > Current time then validate file.

else if “Expires” header is not present and Cache modification time + Revalidate age < Current time then validate file.

else send file unvalidated.

Validation is accomplished by sending an “If-Modified-Since: <timestamp>” header with the request, the Web server will respond with code 304 if the file hasn't been modified.

Since not all Web servers support this, Middleman will also check the Last-Modified header and send a cached response if it maches the cached file's Last-Modified time.

Middleman will honor the following directives sent in the Cache-Control header by the client:

and the following directives from Web servers: