Expand description
Varnish-purge backend for crate::cache_invalidate::PageCacheInvalidator.
Wires the per-page cache-invalidation hook to a Varnish fleet. After a CMS save, each configured Varnish instance receives a BAN request matching the URL so the next request regenerates against the freshly-saved markup.
§Usage
Behind the cache_varnish feature. One arg — the list of
upstream Varnish admin URLs:
ⓘ
use rustango_cms::cache_varnish::VarnishInvalidator;
let inv = VarnishInvalidator::new(vec![
"http://varnish-1.internal:6081".to_owned(),
"http://varnish-2.internal:6081".to_owned(),
]);
let router = rustango_cms::admin::router_with_invalidator(
tera.clone(),
std::sync::Arc::new(inv),
);§VCL setup
Each Varnish instance MUST accept BAN from the CMS host. The canonical VCL:
acl purge {
"127.0.0.1";
"10.0.0.0"/8; # internal CMS subnet
}
sub vcl_recv {
if (req.method == "BAN") {
if (!client.ip ~ purge) {
return (synth(403, "Not allowed"));
}
ban("req.url == " + req.url);
return (synth(200, "Banned"));
}
}Failures are logged through tracing at WARN; the calling
admin handler doesn’t propagate the error (cache-invalidation
is best-effort by trait contract).
Structs§
- Varnish
Invalidator - Send
BANrequests to a fixed list of Varnish backend URLs on every invalidation. The request body is empty; the path carries the URL to purge (matching the VCLban("req.url == ...")rule).