The force cache miss note states:
Forcing cache misses do not evict old content. This means that causes Varnish to have multiple copies of the content in cache. In such cases, the newest copy is always used. Keep in mind that duplicated objects will stay as long as their time-to-live is positive.
I don't want to keep multiple copies in the cache. Is my approach of priming the url valid? Where I manually evict the old content by adding them to the ban lurker. And then forcing a cache miss myself to replace the content which were banned.
acl purge_prime {
"127.0.0.1";
"::1";
}
sub vcl_recv {
if (req.method == "PRIME") {
if (!client.ip ~ purge_prime) {
return(synth(405,"No priming for you. (" + client.ip + ")"));
}
# Add to the ban lurker. Purging existing pages.
ban("obj.http.x-host == " + req.http.host + " && obj.http.x-url == " + req.url);
# Call the backend to fetch new content and add it to the cache.
set req.method = "GET";
set req.hash_always_miss = true;
}
# ... other custom rules.
}
# ... other subroutines below, e.g. adding ban-lurker support etc.
The logic makes sense to me, I'm just worried because no-one else has done it (which I'm assuming there's a reason for).
Is this the wrong approach over using purge with restart, if so what's the best way to prime a url using a single http request?
I suppose that your approach is simply not good because it uses bans. Using purges as opposed to bans will allow you to leverage grace mode.
Restarts are perfectly fine - they will not result in two or more HTTP requests, but rather push the request through the VCL state machine once again.