Skip to content
Documentation

Controlling if and how long Varnish caches your pages

Your environment runs Varnish, an HTTP reverse proxy that sits in front of your application and serves cached responses so pages load faster and your backend handles less traffic. Varnish follows the standard HTTP cache-control headers your application sends — so the caching behaviour of any page is something you control from your application.

How caching is decided by default

When your application returns a response, Varnish looks at its cache-control headers to decide what to do:

  • If the response sends a Cache-Control header or a max-age, Varnish respects it.
  • If the response sends no cache-control header and no max-age, Varnish falls back to a default and caches the response for 120 seconds.

So a page you expect not to be cached will still be cached for the default period if your application doesn't say otherwise.

I want to set how long a page is cached

Have your application send a max-age (in seconds) on the response. For example, to cache a page for one hour:

Cache-Control: public, max-age=3600

I don't want a page to be cached

Have your application send a cache-control header that opts out of caching:

Cache-Control: no-cache, private, must-revalidate

With this header present, Varnish serves the response straight from your application every time instead of storing it.

I want to bypass Varnish entirely

There is no self-service toggle in the platform to switch Varnish off for an environment. You have two options:

  • Control it from your application by sending the no-cache, private, must-revalidate header shown above, so your responses are never stored in the cache.
  • Request a bypass by opening a ticket in the support portal, and we'll arrange it for your environment.

Clearing the cache vs. controlling the cache

These are two different things:

  • Clearing the Varnish cache (the "Clear Varnish" action) empties what's already stored, but it doesn't change what gets cached next. If your headers say a page is cacheable for 120 seconds, it will simply be cached again on the next visit. See Clearing your application's Varnish cache.
  • Controlling the cache means setting the right cache-control headers on your responses, as described above — that's what determines whether and for how long a page is stored in the first place.

If you've cleared Varnish and a page keeps coming back cached incorrectly, the cause is almost always the cache-control headers your application is sending, not the cache itself.

If you need certain cookies to influence caching, see Controlling cacheability of requests with cookies.