Migration questions how to migrate "websocket" and "transparent""

Functionally, the v1 expires directive allowed for:

  • A method to match what requests you want to specify expiration for
  • Dynamic generation of Expires and Cache-Control headers based on provided duration

Currently, in v2, you can replicate some of the functionality right now, just with matchers and the v2 header directive.

The Expires HTTP header is intended to be a fixed datetime after which the response is considered stale. This header can’t easily be replicated dynamically.

However, Cache-Control can be used to hand off the specified duration to the browser, to allow the client to decide dynamically when the content is stale. This part can be done easily in v2.

For example, to state that all .jpg, .jpeg, and .png files should be cached for one day, you would use something like this:

@images {
  file
  path *.jpg *.jpeg *.png
}
header @images Cache-Control "public, max-age=86400"

The empty file matcher just ensures the requested file exists on disk (no point caching a 404 response).

Request matchers (Caddyfile) — Caddy Documentation
header (Caddyfile directive) — Caddy Documentation

2 Likes