How to clear the Varnish cache
Varnish serves a full-page cache of rendered HTML. Clear it when visitors could be seeing stale pages - for example right after a deploy or a content change that the application did not purge on its own.
Before you start
-
SSH access to the host as the application's system user - see SSH access.
-
Varnish enabled on the application - see Configure Varnish.
-
A quiet moment if you can: the whole host serves from the application until the cache refills.
Clear the cache with the TurboStack CLI
Connect over SSH and run:
tscli varnish clear
This empties the entire full-page cache for the host. The next requests are served from your application until the cache refills, so expect a short performance dip.
Note
tscli varnish clear empties the cache; tscli varnish reload is different - it validates and
reloads the Varnish Configuration Language (VCL) after you change a rule (see
Exclude pages from the cache).
Prefer your application's own purge
A full clear is a blunt instrument. Applications that integrate with Varnish (for example Magento)
purge only the pages that changed when you update content, which is far less disruptive than emptying
everything. Use tscli varnish clear when you need a clean slate, or when the application cannot
purge on its own.
After clearing
The first hits are slower while Varnish rebuilds the cache. Warm the important pages by visiting them, or let your sitemap or a crawler do it, before judging performance.
Apply and verify
The clear is immediate. The first request for a page afterwards comes from the application and
shows Age: 0. The second request shows a growing Age, which proves the cache is filling again:
curl -sI https://www.example.com/ | grep -i age
If it did not work
A page that still looks stale with Age: 0 is not served by Varnish at all. The old content then
comes from the OPcache, the application's own cache, a browser cache or a
Content Delivery Network (CDN) in front of the host. A page whose Age never drops was not
cleared - run the command again as the right system user and read its output. See
Why is my site slow?, or
contact support.
Related
- Configure Varnish
- Exclude pages from the Varnish cache
- What is Varnish?
- Clear the Redis cache
- Why is my site slow?
- TurboStack CLI -
tscli varnish clearandtscli varnish reload