Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
3efdc84b
Unverified
Commit
3efdc84b
authored
Jan 29, 2021
by
Dridi Boukelmoune
Committed by
Nils Goroll
Mar 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: First stab at built-in VCL split documentation
parent
7d2e14df
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
5 deletions
+97
-5
vcl-built-in-code.rst
doc/sphinx/users-guide/vcl-built-in-code.rst
+87
-0
vcl-built-in-subs.rst
doc/sphinx/users-guide/vcl-built-in-subs.rst
+3
-1
vcl-syntax.rst
doc/sphinx/users-guide/vcl-syntax.rst
+6
-4
vcl.rst
doc/sphinx/users-guide/vcl.rst
+1
-0
No files found.
doc/sphinx/users-guide/vcl-built-in-code.rst
0 → 100644
View file @
3efdc84b
.. _vcl-built-in-code:
Built-in VCL
============
Whenever a VCL program is loaded, the built-in VCL is appended to it. The
:ref:`vcl-built-in-subs` have a special property, they can appear multiple
times and the result is concatenation of all built-in subroutines.
For example, let's take the following snippet::
sub vcl_recv {
# loaded code for vcl_recv
}
The effective VCL that is supplied to the compiler looks like::
sub vcl_recv {
# loaded code for vcl_recv
# built-in code for vcl_recv
}
This is how it is guaranteed that all :ref:`reference-states` have at least
one ``return (<action>)``.
It is generally recommended not to invariably return from loaded code to
let Varnish execute the built-in code, because the built-in code provides
essentially a sensible default behavior for an HTTP cache.
Built-in subroutines split
--------------------------
It might however not always be practical that the built-in VCL rules take
effect at the very end of a state, so some subroutines like ``vcl_recv``
are split into multiple calls to other subroutines.
By convention, those assistant subroutines are named after the variable
they operate on, like ``req`` or ``beresp``. This allows for instance to
circumvent default behavior.
For example, ``vcl_recv`` in the built-in VCL prevents caching when clients
have a cookie. If you can trust your backend to always specify whether a
response is cacheable or not regardless of whether the request contained a
cookie you can do this::
sub vcl_req_cookie {
return;
}
With this, all other default behaviors from the built-in ``vcl_recv`` are
executed and only cookie handling is affected.
Another example is how the built-in ``vcl_backend_response`` treats a
negative TTL as a signal not to cache. It's a historical mechanism to mark
a response as uncacheable, but only if the built-in ``vcl_backend_response``
is not circumvented by a ``return (<action>)``.
However, in a multi-tier architecture where a backend might be another
Varnish server, you might want to cache stale responses to allow the
delivery of graced objects and enable revalidation on the next fetch. This
can be done with the following snippet::
sub vcl_beresp_stale {
if (beresp.ttl + beresp.grace > 0s) {
return;
}
}
This granularity, and the general goal of the built-in subroutines split
is to allow to circumvent a specific aspect of the default rules without
giving the entire logic up.
Built-in VCL reference
----------------------
A copy of the ``builtin.vcl`` file might be provided with your Varnish
installation but :ref:`varnishd(1)` is the reference to determine the code
that is appended to any loaded VCL.
The VCL compilation happens in two passes:
- the first one compiles the built-in VCL only,
- and the second pass compiles the concatenation of the loaded and built-in
VCLs.
Any VCL subroutine present in the built-in VCL can be extended, in which
case the loaded VCL code will be executed before the built-in code.
doc/sphinx/users-guide/vcl-built-in-subs.rst
View file @
3efdc84b
...
...
@@ -5,7 +5,7 @@
.. _vcl-built-in-subs:
Built
in subroutines
Built
-
in subroutines
====================
Various built-in subroutines are called during processing of client-
...
...
@@ -25,6 +25,8 @@ Common actions are documented in
:ref:`user-guide-vcl_actions`. Actions specific to only one or some
subroutines are documented herein.
A default behavior is provided for all :ref:`reference-states` in the
:ref:`vcl-built-in-code` code.
client side
-----------
...
...
doc/sphinx/users-guide/vcl-syntax.rst
View file @
3efdc84b
...
...
@@ -87,13 +87,15 @@ down for, uhm, examples.
Built in subroutines
~~~~~~~~~~~~~~~~~~~~
Varnish has quite a few built
in subroutines that are called for each
transaction as it flows through Varnish. These built
in subroutines are all
named ``vcl_*`` and are explained in :ref:`vcl-built-in-subs`.
Varnish has quite a few built
-
in subroutines that are called for each
transaction as it flows through Varnish. These built
-in subroutines are
all
named ``vcl_*`` and are explained in :ref:`vcl-built-in-subs`.
Processing in built
in subroutines ends with ``return (<action>)``
Processing in built
-
in subroutines ends with ``return (<action>)``
(see :ref:`user-guide-vcl_actions`).
The :ref:`vcl-built-in-code` also contains custom assistant subroutines
called by the built-in subroutines, also prefixed with ``vcl_``.
Custom subroutines
~~~~~~~~~~~~~~~~~~
...
...
doc/sphinx/users-guide/vcl.rst
View file @
3efdc84b
...
...
@@ -41,6 +41,7 @@ code commented out in the file `builtin.vcl` that ships with Varnish Cache.
vcl-syntax
vcl-built-in-subs
vcl-built-in-code
vcl-variables
vcl-actions
vcl-backends
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment