VMOD-VARIABLE

NAME

vmod-variable
− variable support for Varnish Cache

SYNOPSIS

import
variable [PATH];

DESCRIPTION

This module
provides enhanced variable support for VCL
scripts.

There are two
kind of variables: session-specific and
global. Session-specific variables have a lifespan of
one HTTP session and cease to exist when it is closed. Such
variables can be of almost any VCL type: STRING,
INT, REAL, or DURATION. For each of
these types a pair of functions is provided for setting the
variable and obtaining its value.

Two functions
are provided for setting several variables at once. The
regset function parses its input according to a
regular expression and sets variables to the captured
strings, using sophisticated declaration patterns.

The
queryset function parses its input as a HTTP query
string and sets the variables defined in it.

The
global variables are shared between all threads and
sessions. They can hold only string values.

VMOD_VARIABLE VS. VMOD_VAR

This module
doesn’t share any code with vmod_var. Compared
with the latter, it provides the following new features:

1.

Both Varnish 3 and 4 are supported;

2.

Variables are stored in hash tables with open
addressing, to speed up accesses (vmod_var keeps them
in singly-linked lists).

3.

Functions for testing existence and types of variables,
and for unsetting a variable: defined(),
type_of(), and unset().

The parameter
vardcl contains one or more comma-separated
declarations. Each declaration is a variable name,
optionally followed by the following constructs, in that
order: :TYPE and =REPL.

The
:TYPE construct declares the type of the
variable. TYPE can be one of STRING,
INT, REAL, DURATION, or any
abbreviation of these (case-insensitive). E.g. x:r
means that the variable x is of REAL type. If
this part is omitted, STRING type is assumed.

The
=REPL suffix instructs the function to set the
variable to the value computed according to REPL,
which is a replacement expression in the sense of
regsub.

If this part is
omitted, the variable is initialized to the value of the
Nth capture group from regex, where N
is the position of that declaration in vardcl.

Both parts can
be used together, for example: time:d=\1m will set
the time variable to the duration obtained by
concatenating first captured group with the suffix
m.