File: //usr/share/doc/varnish/html/reference/vmod_purge.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>VMOD purge - Varnish Purge Module — Varnish version 6.4.0 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '6.4.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Varnish version 6.4.0 documentation" href="../index.html" />
<link rel="up" title="The Varnish Reference Manual" href="index.html" />
<link rel="next" title="VMOD std - Varnish Standard Module" href="vmod_std.html" />
<link rel="prev" title="VMOD proxy - Varnish Module to extract TLV attributes from PROXYv2" href="vmod_proxy.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="vmod_std.html" title="VMOD std - Varnish Standard Module"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="vmod_proxy.html" title="VMOD proxy - Varnish Module to extract TLV attributes from PROXYv2"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">Varnish version 6.4.0 documentation</a> »</li>
<li><a href="index.html" accesskey="U">The Varnish Reference Manual</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="vmod-purge-varnish-purge-module">
<span id="vmod-purge-3"></span><h1>VMOD purge - Varnish Purge Module<a class="headerlink" href="#vmod-purge-varnish-purge-module" title="Permalink to this headline">¶</a></h1>
<div class="section" id="synopsis">
<h2>SYNOPSIS<a class="headerlink" href="#synopsis" title="Permalink to this headline">¶</a></h2>
<pre class="literal-block">
import purge [as name] [from "path"]
<a class="reference internal" href="#purge-hard"><em>INT hard()</em></a>
<a class="reference internal" href="#purge-soft"><em>INT soft(DURATION ttl, DURATION grace, DURATION keep)</em></a>
</pre>
</div>
<div class="section" id="description">
<h2>DESCRIPTION<a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h2>
<p><em>vmod_purge</em> contains functions that offer a finer-grained control
than <tt class="docutils literal"><span class="pre">return(purge)</span></tt> from <tt class="docutils literal"><span class="pre">vcl_recv{}</span></tt>. The functions can only be
called from <tt class="docutils literal"><span class="pre">vcl_hit{}</span></tt> or <tt class="docutils literal"><span class="pre">vcl_miss{}</span></tt> and they should in general
be used in both to ensure that all variants of a same object are taken
care of.</p>
</div>
<div class="section" id="example">
<h2>EXAMPLE<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><pre>sub vcl_recv {
if (req.method == "PURGE") {
if (client.ip !~ purge_acl) {
return (synth(405));
}
return (hash);
}
}
sub my_purge {
set req.http.purged = purge.hard();
if (req.http.purged == "0") {
return (synth(404));
}
else {
return (synth(200));
}
}
sub vcl_hit {
if (req.method == "PURGE") {
call my_purge;
}
}
sub vcl_miss {
if (req.method == "PURGE") {
call my_purge;
}
}
sub vcl_synth {
if (req.method == "PURGE") {
if (req.http.purged) {
set resp.http.purged = req.http.purged;
}
return (deliver);
}
}</pre>
</div>
<div class="section" id="int-hard">
<span id="purge-hard"></span><h3>INT hard()<a class="headerlink" href="#int-hard" title="Permalink to this headline">¶</a></h3>
<p>This is equivalent to <tt class="docutils literal"><span class="pre">return(purge)</span></tt> but explicitly called from
<tt class="docutils literal"><span class="pre">vcl_hit{}</span></tt> and <tt class="docutils literal"><span class="pre">vcl_miss{}</span></tt>. It returns the number of purged
objects.</p>
<p>Example:</p>
<div class="highlight-python"><pre>set req.http.purged = purge.hard();</pre>
</div>
</div>
<div class="section" id="int-soft-duration-ttl-duration-grace-duration-keep">
<span id="purge-soft"></span><h3>INT soft(DURATION ttl, DURATION grace, DURATION keep)<a class="headerlink" href="#int-soft-duration-ttl-duration-grace-duration-keep" title="Permalink to this headline">¶</a></h3>
<div class="highlight-python"><pre>INT soft(DURATION ttl=0, DURATION grace=-1, DURATION keep=-1)</pre>
</div>
<p>Sets the <em>ttl</em>, <em>grace</em> and <em>keep</em>.</p>
<p>By default, <em>ttl</em> is set to 0 with <em>grace</em> and <em>keep</em> periods left
untouched. Setting a negative value for <em>grace</em> or <em>keep</em> periods
leaves them untouched. Setting all three parameters to <tt class="docutils literal"><span class="pre">0</span></tt> is
equivalent to a hard purge. It can only be called from <tt class="docutils literal"><span class="pre">vcl_hit{}</span></tt>
or <tt class="docutils literal"><span class="pre">vcl_miss{}</span></tt>. It returns the number of soft-purged objects.</p>
</div>
</div>
<div class="section" id="see-also">
<h2>SEE ALSO<a class="headerlink" href="#see-also" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><a class="reference internal" href="vcl.html#vcl-7"><em>VCL</em></a></li>
</ul>
</div>
<div class="section" id="copyright">
<h2>COPYRIGHT<a class="headerlink" href="#copyright" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><pre>Copyright (c) 2017 Varnish Software AS
All rights reserved.
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
SPDX-License-Identifier: BSD-2-Clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="vmod_proxy.html"
title="previous chapter">VMOD proxy - Varnish Module to extract TLV attributes from PROXYv2</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="vmod_std.html"
title="next chapter">VMOD std - Varnish Standard Module</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/reference/vmod_purge.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="vmod_std.html" title="VMOD std - Varnish Standard Module"
>next</a> |</li>
<li class="right" >
<a href="vmod_proxy.html" title="VMOD proxy - Varnish Module to extract TLV attributes from PROXYv2"
>previous</a> |</li>
<li><a href="../index.html">Varnish version 6.4.0 documentation</a> »</li>
<li><a href="index.html" >The Varnish Reference Manual</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2010-2014, Varnish Software AS.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>