14/03/2024
In the world of web servers and caching, Varnish Configuration Language (VCL) serves as the backbone for optimizing content delivery. Understanding when and how to utilize key VCL subroutines like RECV, FETCH, and DELIVER is pivotal for crafting efficient caching strategies
VCL states :
This article zooms into the steps of dealing with requests using Varnish, shown in a diagram. We’ll mainly look at three important parts: RECV, FETCH, and DELIVER.
RECV, FETCH, and DELIVER.
RECV :
We refer it as a request type, used when we receive the request.
In this condition we have access to the following variables ( to me they are more like objects )
client.*
server.*
reg.*
FETCH :
We refer it as a cache type, used when we cache the request
client.*
server.*
reg.*
resp.*
beresp.*
stands for « Back-end response »
DELIVER:
We refer it as a response type, used when we modify the response before sending it to the end user.
client.*
server.*
reg.*
resp.*
resp.*
is for the response we send back to users.
Examples of what we can access :
client.ip
client.port
client.requests
server.datacenter
server.ip
Server.port
Req.url
Req.host
req.http.*
VLC methods and subroutines
RECV runs after the Delivery Node gets a request.
FETCH runs after we get a backend response & before we cache the object.
DELIVER runs before we send the response to the end user.
Takeaways
• Using the Ul allows you to add logic and configurations into the RECV, FETCH, & DELIVER subroutines.
• RECV runs after the Delivery Node gets a request.
• FETCH runs after we get a backend response & before we cache the object.
• DELIVER runs before we send the response to the end user.
• Logic and configs in the Ul fall into three types: Request – Cache – Response
• Each of the above three type has different variables available to reference.