Built in subroutinesVcl_recv
This subroutine is called after a complete client request has been received. It decides whether to process the request, how to handle the request, and which backend to use.
It can also be used to modify requests, something that is often done on its own.
The vcl_recv subroutine can be terminated by calling return () through the following keywords:
Synth (Status code, reason) return a synthetic object with the specified status code to the client and abandon the request. returns a person that uses the specified status code for the object to the client or discards the request. pass switch to pass mode. control will eventually pass to vcl_pass. processing jump to Vcl_passpipe switch to pipe mode. Control will eventually pass to vcl_pipe. Handling Jump to Vcl_pipehash continue processing the object as a potential candidate for caching. Passes the control over to vcl_hash. processing jumps to Vcl_hash, finds objects in the cache, or hits if there is, Purge purge the object and it ' S variants. control passes through vcl_hash to vcl_purge. deletes the object and its variants. Control pass through Vcl_hash to Vcl_purge
Vcl_pipe
Called when the pipe mode is entered. Pass the request directly to the back-end host and return the backend response as it is to the client
The vcl_pipe subroutine can be terminated by calling return () through the following keywords:
Synth (status code, reason) Return a synthetic object with the specified status code to the client and abandon the Reque St. Returns a person that uses the specified status code for the object to the client or discards the request. Pipe Proceed with pipe mode. Working with PIP mode
Vcl_pass
This function is called when entering pass mode, which is used to pass the request directly to the backend host, but the response of the backend host does not cache the direct return client;
The Vcl_pass subroutine can be terminated by calling return () through the following keywords:
Synth (status code, reason) Return a synthetic object with the specified status code to the client and abandon the Reque St. Returns a person that uses the specified status code for the object to the client or discards the request. Fetch Proceed with Pass mode. Continue with Pass mode Restart Restart the transaction. Increases the restart counter. If the number of restarts is higher than max_restarts Varnish emits a guru meditation error. Restart the transaction. The restart counter is added. If the number of restarts is higher than max_restarts, Varnish will return the authoritative default error.
Vcl_hit
After the lookup instruction is executed, the function is automatically called after the requested content is found in the cache;
The Vcl_hit subroutine can be terminated by calling return () through the following keywords:
Restart Restart the transaction. Increases the restart counter. If the number of restarts is higher than max_restarts Varnish emits a guru meditation error. Restart the transaction. The restart counter is added. If the number of restarts is higher than max_restarts, Varnish will return the authoritative default error. Deliver deliver the object. Control passes to Vcl_deliver. Pass the object, using Vcl_deliver processing. Synth (status code, reason) Return a synthetic object with the specified status code to the client and abandon the Reque St. Returns a person that uses the specified status code for the object to the client or discards the request.
Vcl_miss
This method is called automatically when the requested content is not found in the cache after the lookup instruction is executed, which can be used to determine whether the content needs to be fetched from the backend server and from which backend;
The Vcl_miss subroutine can be terminated by calling return () through the following keywords:
Synth (Status code, reason) return a synthetic object with the specified status code to the client and abandon the request. returns a person that uses the specified status code for the object to the client or discards the request. pass switch to pass mode. control will eventually pass to vcl_pass. processing jump to Vcl_passfetch retrieve the requested object from the backend. control will eventually pass to vcl_backend_fetch. gets the request object from the back end. Control is eventually passed to the Vcl_backend_fetch. restart restart the transaction. increases the restart Counter. if the number of restarts is higher than max_restarts varnish emits a guru meditation error. Restart the transaction. The restart counter is added. If the number of restarts is higher than max_restarts, Varnish will return the authoritative default error.
Vcl_hash
This function is called when a hash value is created for the request after the VCL_RECV call, and the hash value is used as the key for the search cache object in the varnish;
The Vcl_hash subroutine can be terminated by calling return () through the following keywords:
Lookup looks up the object in the cache. Control passes to Vcl_miss, Vcl_hit or Vcl_purge. Finds an object from the cache. Control is passed to Vcl_miss, Vcl_hit, or Vcl_purge.
Vcl_purge
The pruge operation executes after calling this function, all his variants will be evaded;
The Vcl_purge subroutine can be terminated by calling return () through the following keywords:
Synth (status code, reason) Return a synthetic object with the specified status code to the client and abandon the Reque St. Returns a person that uses the specified status code for the object to the client or discards the request. Restart Restart the transaction. Increases the restart counter. If the number of restarts is higher than max_restarts Varnish emits a guru meditation error. Restart the transaction. The restart counter is added. If the number of restarts is higher than max_restarts, Varnish will return the authoritative default error.
Vcl_deliver
This method is called before the content of the request is found in the cache and sent to the client;
The vcl_deliver subroutine can be terminated by calling return () through the following keywords:
Deliver deliver the object to the client. Passes the object to the client. Restart Restart the transaction. Increases the restart counter. If the number of restarts is higher than max_restarts Varnish emits a guru meditation error. Restart the transaction. The restart counter is added. If the number of restarts is higher than max_restarts, Varnish will return the authoritative default error.
Vcl
BackendFetch
Call this function before sending a request to the back-end host to modify the request to the backend;
The vclbackendfetch subroutine can be terminated by calling return () through the following keywords:
Fetch fetch the object from the backend. Gets the object from the backend Abandon Abandon the backend request and generates an error. Discards back-end requests and generates an error page.
Vcl
BackendResponse
This function can be called after the response of the backend host is obtained;
The vclbackendresponse subroutine can be terminated by calling return () through the following keywords:
Deliver possibly insert the object into the cache and then deliver it to the Control would eventually pass to Vcl_deliver. You can insert an object into the cache and then pass it to the controller, which is eventually passed to Vcl_deliver. Abandon abandon the backend request and generates an error. Discards back-end requests and generates an error page. Retry retry the backend transaction. Increases the retries counter. If the number of retries is higher than max_retries Varnish emits a guru meditation error. Restart the transaction. The restart counter is added. If the number of restarts is higher than max_restarts, Varnish will return the authoritative default error.
Vcl
BackendError
This function is called when the source file fails to get from the backend host;
The vclbackenderror subroutine can be terminated by calling return () through the following keywords:
Deliver deliver the error. Delivery error page Retry Retry the backend transaction. Increases the retries counter. If the number of retries is higher than max_retries Varnish emits a guru meditation error. Restart the transaction. The restart counter is added. If the number of restarts is higher than max_restarts, Varnish will return the authoritative default error.
Vcl_synth
The call is to return a defined object, the defined object is generated in the VCL, and is not fetched from the backend. Typical is the use of the synthetic () function;
The Vcl_synth subroutine can be terminated by calling return () through the following keywords:
Deliver deliver the object. If the object has a positive TTL then the object is also stored in cache. The object is passed, and if the object has a TTL set, it is also stored in the cache. Restart restart processing the object. Restarts the processing of the object.
Vcl_init
This function is called when VCL is loaded, and is often used to initialize the varnish module (vmods);
The Vcl_init subroutine can be terminated by calling return () through the following keywords:
OK Normal return, VCL continues loading. Normal return, VCL continues to load.
Vcl_fini
When all requests leave the current VCL, and the current VCL is discarded, call this function, which is often used to clean up the varnish module;
The Vcl_init subroutine can be terminated by calling return () through the following keywords:
OK Normal return, VCL'll be discarded. Normal return, VCL will no longer be used.
Varnish 4.0 Official document translation 14-built in subroutines