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
e98e8e64
Commit
e98e8e64
authored
Feb 12, 2021
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documentation updates for changed `vcl_hash{}` / `hash_data()`
parent
001279eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
14 deletions
+33
-14
changes.rst
doc/changes.rst
+9
-0
vcl.rst
doc/sphinx/reference/vcl.rst
+3
-1
vcl-built-in-subs.rst
doc/sphinx/users-guide/vcl-built-in-subs.rst
+3
-2
vcl-hashing.rst
doc/sphinx/users-guide/vcl-hashing.rst
+18
-11
No files found.
doc/changes.rst
View file @
e98e8e64
...
@@ -30,6 +30,15 @@ release process.
...
@@ -30,6 +30,15 @@ release process.
Varnish Cache Next (2021-03-15)
Varnish Cache Next (2021-03-15)
================================
================================
* `hash_data()` can be called from `vcl_recv`, in which case
`vcl_hash` is not called. This allows `vcl_recv` and
backends to take the object identity into account, for
instance when choosing backend and grace periods.
* `hash_data()` calculates the hash-key differently than previously.
This means that persistent storage will be lost, and it may break
very specific `*.vtc` test-scripts.
* counters MAIN.s_req_bodybytes and VBE.*.tools.beresp_bodybytes
* counters MAIN.s_req_bodybytes and VBE.*.tools.beresp_bodybytes
are now always the number of bodybytes moved on the wire.
are now always the number of bodybytes moved on the wire.
...
...
doc/sphinx/reference/vcl.rst
View file @
e98e8e64
...
@@ -478,7 +478,9 @@ hash_data(input)
...
@@ -478,7 +478,9 @@ hash_data(input)
~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~
Adds an input to the hash input. In the built-in VCL ``hash_data()``
Adds an input to the hash input. In the built-in VCL ``hash_data()``
is called on the host and URL of the request. Available in ``vcl_hash``.
is called on the host and URL of the request.
Available in ``vcl_hash`` or ``vcl_recv``. If used in ``vcl_recv``
``vcl_hash`` will not be called.
synthetic(STRING)
synthetic(STRING)
~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~
...
...
doc/sphinx/users-guide/vcl-built-in-subs.rst
View file @
e98e8e64
...
@@ -129,8 +129,9 @@ of the following keywords:
...
@@ -129,8 +129,9 @@ of the following keywords:
vcl_hash
vcl_hash
~~~~~~~~
~~~~~~~~
Called after `vcl_recv` to create a hash value for the request. This is
Called after `vcl_recv` to create a hash value for the request,
used as a key to look up the object in Varnish.
unless `vcl_recv` already did that.
This is used as the key to store and look up objects in the cache.
The `vcl_hash` subroutine may terminate with calling ``return()`` with one
The `vcl_hash` subroutine may terminate with calling ``return()`` with one
of the following keywords:
of the following keywords:
...
...
doc/sphinx/users-guide/vcl-hashing.rst
View file @
e98e8e64
Hashing
Hashing
-------
-------
Internally, when Varnish stores content in the cache it stores the object
Internally, when Varnish stores content in the cache indexed by a hash
together with a hash key to find the object again. In the default setup
key used to find the object again. In the default setup
this key is calculated based on the content of the *Host* header or the
this key is calculated based on `URL`, the `Host:` header, or
IP address of the server and the URL.
if there is none, the IP address of the server::
Behold the `default vcl`::
sub vcl_hash {
sub vcl_hash {
hash_data(req.url);
hash_data(req.url);
...
@@ -18,7 +16,7 @@ Behold the `default vcl`::
...
@@ -18,7 +16,7 @@ Behold the `default vcl`::
return (lookup);
return (lookup);
}
}
As you can see it first
checks in `req.url`
then `req.http.host` if
As you can see it first
hashes `req.url` and
then `req.http.host` if
it exists. It is worth pointing out that Varnish doesn't lowercase the
it exists. It is worth pointing out that Varnish doesn't lowercase the
hostname or the URL before hashing it so in theory having "Varnish.org/"
hostname or the URL before hashing it so in theory having "Varnish.org/"
and "varnish.org/" would result in different cache entries. Browsers
and "varnish.org/" would result in different cache entries. Browsers
...
@@ -42,7 +40,16 @@ And then add a `vcl_hash`::
...
@@ -42,7 +40,16 @@ And then add a `vcl_hash`::
hash_data(req.http.X-Country-Code);
hash_data(req.http.X-Country-Code);
}
}
As the default VCL will take care of adding the host and URL to the hash
Because there is no `return(lookup)`, the builtin VCL will take care
we don't have to do anything else. Be careful calling ``return (lookup)``
of adding the URL, `Host:` or server IP# to the hash as usual.
as this will abort the execution of the default VCL and Varnish can end
up returning data based on more or less random inputs.
If `vcl_hash` did return, ie::
sub vcl_hash {
hash_data(req.http.X-Country-Code);
return(lookup);
}
then *only* the country-code would matter, and Varnish would return
seemingly random objects, ignoring the URL, (but they would always
have the correct `X-Country-Code`).
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