Skip to content

Traffic Server Caching

Geoffroy Noël edited this page Oct 24, 2019 · 8 revisions

Apache Traffic Server is a service that caches html pages on our dev, stg and liv sites. It works a level above the web server and Django.

You sometimes may need to clear the cache if you received old version of the html pages but you have since updated the site.

sudo -- sh -c 'service trafficserver stop && traffic_server -C clear && service trafficserver start'

What are the caching policies?

TrafficServer caches content and response headers from web server and use that to determine when to request a new version.

See logic here:

https://docs.trafficserver.apache.org/en/latest/admin-guide/configuration/cache-basics.en.html#http-object-freshness

In practice, it seems that with our default configuration the static files are cached for 10% of the period between the file timestamp on disk and the last time the timestamp was checked by TS. So if an asset hasn't been updated for a year, a new version may not be requested for up to a month after its deployment (even if TS has been restarted or its cache cleared recently). That's why it's best to always clear the cache after any live deployment, especially after any package upgrade (Wagtail, Django).

https://docs.trafficserver.apache.org/en/latest/admin-guide/configuration/cache-basics.en.html#modifying-aging-factor-for-freshness-computations

Never cache some paths

To prevent caching a specific path, add the following the rule to /etc/trafficserver/cache.config :

url_regex=/search.* action=never-cache

(Note, examples in trafficserver doc wrongly include the domain in the regex, it should only use the webpath)

What's Wagtail caching policy?

It seems that by default wagtail only returns the 'Date' in the response header.