Skip to main content
Warning This document has not been updated for a while now. It may be out of date.
Last updated: 24 Jan 2024

Purge a page from cache

Background

Fastly caches HTTP resources such as HTML pages, images and scripts on www.gov.uk and assets.publishing.service.gov.uk based on the Cache-Control headers that we serve from our origin site. Most pages are cached for 5 minutes, so when changes are published it may take up to 5 minutes for users to see those changes.

Check the cache headers of a page

You can check the cache headers of a page or any other HTTP resource using curl:

$ curl -sI https://www.gov.uk/vat-rates | grep -Ei 'cache-control|age:|x-cache'
age: 107
cache-control: max-age=300, public,private
x-cache: HIT
x-cache-hits: 1
  • age is time in seconds since the resource was cached
  • cache-control defines where and when a resource can be cached and for how long
  • x-cache indicates whether the request was served from cache
  • x-cache-hits is the number of cache hits at that particular Fastly point of presence

Purge a page from the Fastly CDN

If an item urgently needs to be removed from the cache, you can issue a purge request.

If something was published that should not have been published, consider whether there has been a notifiable data breach and if so, make sure that someone is handling the matter.

  1. Log into https://manage.fastly.com/. If you don’t have an account, ask your tech lead or a member of the senior tech team.
  2. Under All services, choose the appropriate service. For example, Production GOV.UK for www.gov.uk or Production Assets for assets.publishing.service.gov.uk.
  3. From the “Purge” drop-down button near the top left of the page, choose “Purge URL”.
  4. Enter the full path of the resource to purge (that is, everything after the hostname in the URL) and choose Purge.

Purging all objects from the Fastly CDN

If possible, check with a member of the senior tech team before doing this in production.

  1. Log into https://manage.fastly.com/.
  2. Under All services, choose the appropriate service. For example, Production GOV.UK for www.gov.uk or Production Assets for assets.publishing.service.gov.uk.
  3. From the “Purge” drop-down button near the top left of the page, choose “Purge all”.
  4. The UI will ask you for confirmation before issuing the purge request.

Purge a page from the standby CloudFront CDN

In addition to our primary CDN (Fastly), we also have a standby CDN set up on CloudFront. This standby CDN is only intended to be used during a Fastly outage, so there’s a limited number of situations in which you would need to purge its cache.

If an item urgently needs to be removed from the cache, you can create an invalidation from the AWS console.

  1. Log into the AWS console with gds aws govuk-production-poweruser -l.
  2. Under the CloudFront distributions page, choose the appropriate distribution: WWW for www.gov.uk or Assets for assets.publishing.service.gov.uk.
  3. Select the “Invalidations” tab, and click “Create invalidation”.
  4. Enter the full paths of all resources to purge (that is, everything after the hostname in the URL). You can optionally use wildcards (*). To purge all objects, enter the path /*.
  5. Click “Create invalidation”.

Further reading

See Fastly’s documentation on purging.