Varnishのcacheをpurgeする
cacheをpurgeする
いくつかの方法がある
全てのcacheをpurgeする
varnishをreloadするコマンドを実行すればいい
コマンドは環境によって異なる
$ systemctl restart varnish
$ service varnish restart
PURGE methodを使う
特定の1つのURLをpurgeする
事前準備
purge用のVCLのaclを定義しておく
code:default.vcl
acl purge {
"localhost";
"127.0.0.1";
}
PURGEを送れるIPアドレスを制限しておく
ちなみにこのpurgeは予約語ではないmrsekut.icon
purge用の実装を定義しておく
code:default.vcl
sub vcl_recv {
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return(synth(405,"Not allowed."));
}
return (purge);
}
}
PURGEでrequestを送る
aclで指定した環境の中で以下を実行
$ curl -X PURGE https://example.com/hoge
参考
Purging and banning — Varnish version trunk documentation
Example VCL template - Varnish Developer Portal
2と8に書いている
参考
Purging and banning — Varnish version trunk documentation
docs
Varnishキャッシュのクリアについてメモ – Siguniang's Blog
versionが明記されていないが、恐らく内容がかなり古い
#WIP
ban()を使う
これよくわからん #??
対象のものがban listに追加される
この時点ではメモリ内に残っている
次にrequestを送った時は、originから取得される
varnishadmで呼べる
$ varnishadm ban req.http.host == example.com '&&' req.url '~' '\\.png$'
varnishadm> ban.listで確認できる
https://varnish-cache.org/docs/trunk/reference/vmod_std.html#std-ban
Purging and banning — Varnish version trunk documentation
https://qiita.com/koudaiii/items/6a0efa024842cd48e2fb#キャッシュクリアの方法
古い
https://siguniang.wordpress.com/2014/01/09/notes-on-varnish-cache-validation/
古い
使いどきがわからない #??
forced cache miss
req.hash_always_missを使う
cache内のobjectをrequest時のものに更新する
Purging and banning — Varnish version trunk documentation
#??
3種類あるけど何が違うねん
example.com/v2/*みたいな感じで指定してpurgeしたい