Default Functions
VCL Subroutines
Built-in subroutines called at key points in the request lifecycle. Override them to control caching, routing, and response behaviour.
Request flow: vcl_recv → vcl_hash → vcl_hit / vcl_miss → vcl_backend_fetch → vcl_backend_response → vcl_deliver (or vcl_synth at any point)
vcl_recv
Called at the start of every incoming request, before any cache lookup. Use it to normalise the request, strip unnecessary headers, or decide whether the request should bypass the cache.
You can also assign a backend here or do it in the vcl_backend_fetch subroutine.
vcl_hash
Called after vcl_recv, immediately before the cache lookup.
Add data to the hash to create separate cache entries for the same URL, for example, per-host or per-device-type variations.
Warning: Every unique hash key is a separate cache object. Adding a high-cardinality value (e.g. a session token) will produce one cache entry per user, effectively disabling caching for that resource.
vcl_miss
Called after a cache lookup that found no valid object. At this point, the request will continue to the backend to retrieve the object.
vcl_hit
Called after a successful cache lookup. The cached object is available. Normally does nothing; override it to force a re-fetch under certain conditions
vlc_deliver
Called just before the response is sent to the client. Use it to add, remove, or rewrite response headers. The object has already been fetched or retrieved from cache at this point.
vcl_synth
Called when a return(synth(status, reason)) action is issued from any other subroutine (like our call redirect_request; action).
On the origin side
vcl_backend_fetch
Called before Varnish sends a request to the origin. This is the correct place to select a backend and modify backend request headers. Only runs on cache misses and pass requests, cache hits never reach this subroutine.
vcl_backend_response
Called when the backend response headers arrive. Use it to set TTLs, override Cache-Control, remove headers that would prevent caching, or discard a bad response.
The rest of the predefined functions in Varnish Enterprise Plus are not allowed to be modified by the user in Transparent CDN, to ensure the security and stability of our clients' sites at all times. However, you can check them out here.
Last updated
Was this helpful?
