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
cf333085
Commit
cf333085
authored
Apr 11, 2014
by
Federico G. Schwindt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vcl_hash() returns lookup now
While here fmt(1) the text.
parent
6cb0f12a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
28 deletions
+26
-28
vcl-hashing.rst
doc/sphinx/users-guide/vcl-hashing.rst
+26
-28
No files found.
doc/sphinx/users-guide/vcl-hashing.rst
View file @
cf333085
Hashing
Hashing
-------
-------
Internally, when Varnish stores content in the cache it stores the object
together with a hash
Internally, when Varnish stores content in the cache it stores the object
key to find the object again. In the default setup this key is
together with a hash key to find the object again. In the default setup
calculated based on the content of the *Host* header or the IP address
this key is calculated based on the content of the *Host* header or the
of the server and the URL.
IP address
of the server and the URL.
Behold the `default vcl`::
Behold the `default vcl`::
sub vcl_hash {
sub vcl_hash {
hash_data(req.url);
hash_data(req.url);
if (req.http.host) {
if (req.http.host) {
hash_data(req.http.host);
hash_data(req.http.host);
} else {
} else {
hash_data(server.ip);
hash_data(server.ip);
}
}
return (hash
);
return (lookup
);
}
}
As you can see it first checks in `req.url` then `req.http.host` if
it
As you can see it first checks in `req.url` then `req.http.host` if
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
however, tend to lowercase hostnames.
however, tend to lowercase hostnames.
...
@@ -29,22 +29,20 @@ serve up different content to different clients based on arbitrary
...
@@ -29,22 +29,20 @@ serve up different content to different clients based on arbitrary
criteria.
criteria.
Let's say you want to serve pages in different languages to your users
Let's say you want to serve pages in different languages to your users
based on where their IP address is located. You would need some Vmod
based on where their IP address is located. You would need some Vmod to
to get a country code and then put it into the hash. It might look
get a country code and then put it into the hash. It might look like this.
like this.
In `vcl_recv`::
In `vcl_recv`::
set req.http.X-Country-Code = geoip.lookup(client.ip);
set req.http.X-Country-Code = geoip.lookup(client.ip);
And then add a `vcl_hash`::
And then add a `vcl_hash`::
sub vcl_hash {
sub 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
As the default VCL will take care of adding the host and URL to the hash
hash we don't have to do anything else. Be careful calling
we don't have to do anything else. Be careful calling ``return (lookup)``
``return(hash)`` as this will abort the execution of the default VCL and
as this will abort the execution of the default VCL and Varnish can end
Varnish can end up returning data based on
up returning data based on more or less random inputs.
more or less random inputs.
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