Skip to content

Clearing Varnish

Intro

To purge the cache on the frontend server run:

/usr/bin/varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 ban "req.url ~ .*"

Varnish matches the cached objects' URLs against the regular expression .*.

⚠️ The Varnish cache should NEVER be cleared entirely (.*) when running in production as that would mean that all the requests must be served by the middles, increasing the load. Instead, in case this is required, purge the cache selectively, only a few URLs at a time.

To purge Varnish cache more selectively:

  • For the category economia:
/usr/bin/varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 ban "req.url ~ /economia"
  • For all category economia and all its subcategories + articles in economia category:
/usr/bin/varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 ban "req.url ~ /economia/.*"
  • For purging individual boards: each of the boards has a slug (the developer knows the slugs of boards). The boards are served by the URL: /page/_BOARD_SLUG.html . So the request to purge the cache for a specific board is:
/usr/bin/varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 ban "req.url ~ /page/__BOARD_SLUG__.html"

Symfony app commands

A few commands were developed to invalidate the configured frontend cache, be it Varnish or other (Fastly/Akamai). These commands add a job to the resque. You can check the status of the job by adding -f (follow) option.

Invalidate path command

./app/admin/console wf:cms:frontend-cache:invalidate-path -f "/"

Invalidate tag command

./app/admin/console wf:cms:frontend-cache:invalidate-tag -f assets