Skip to main content

Varnish

Caches whole responses in front of your site, so a hit never reaches it

Varnish, as wodby now ships it — their image is called vinyl, which is why the service's id is vinyl. It caches whole responses in front of whatever answers for the site: Nginx for a PHP application, the application itself for Node.js or Go. A hit never reaches it at all.

It can sit on the web server or on a machine of its own, and with more than one web server it spreads the misses across all of them. See Shapes.

What it caches is what your application says may be cached. A page sent with Cache-Control: max-age is kept that long; one sent without is kept for two minutes unless you set VARNISHD_PARAM_DEFAULT_TTL. A page that is past its time may still be served for a short while as a fresh copy is fetched behind it, so a slow page is slow once rather than for every visitor who asks at once.

A request has 60 seconds to start answering through Varnish, whatever Nginx and PHP allow. Work that takes longer belongs in a worker.

#Purging

Your application finds it at VARNISH_HOST, port 6081. A purge sent there from inside the stack needs no key; one arriving from outside needs VARNISH_PURGE_KEY in an X-VC-Purge-Key header. Both are in the environment. For Drupal's purger, see the snippet.

#Rules of your own

Two files in your repository add to the cache policy rather than replacing it:

File Added to
.vallic/varnish/recv.vcl vcl_recv — what to do with a request: a path never to cache, a cookie to ignore
.vallic/varnish/backend-response.vcl vcl_backend_response — what to do with an answer: a lifetime for one route, a header to keep

Each is read from the environment's branch and holds rules for that one subroutine, at most 8 KB. A file may not declare a backend, define vcl_init, import a module or include another file — where requests go, and what runs inside the cache, are the platform's. A file that does is left out, and the policy runs without it. The assembled policy is compiled before it replaces the one running, and a policy that does not compile is not loaded.

#Versions

Version Status
8.0 Supported, and the default
6.0 Deprecated — still runs, but move to something newer

A deprecated version still runs and is still what some sites are on. It is listed so you can move before it goes, rather than finding out on the morning a build stops resolving it.

Pin the version, not the build: name 8.0 and the platform matches it to the current build, so a security rebuild reaches you without anybody editing a repository.

#What you can change

In vallic.yaml — what each one does is on Service settings:

services:
  - vinyl:
      version: '8.0'
      environment:
        VARNISHD_PARAM_DEFAULT_TTL: …
        VARNISH_BACKEND_GRACE: …
        VARNISH_CACHE_PER_COUNTRY: …
        VARNISH_MOBILE_SEPARATE_CASH: …
        VARNISH_KEEP_ALL_PARAMS: …

Anything not on this list refuses the deploy, naming the variable — rather than being accepted and quietly ignored.