首页 > 解决方案 > Varnish script for warming cache

问题描述

I am using this script:

#!/bin/bash
wget --output-document=/dev/null --header='Cache-Control: no-cache' --tries=1 --quiet --base=http://example.com --input-file=/path/to/urls.txt

which is calling some urls I want to warm in Varnish from a txt file.

For this to work I added in

Varnish vcl

this code:

acl warmuper_ip {
    "10.20.30.40";
}

sub vcl_recv {
    # the script varnish-cache-warmup.sh must always refresh the cache
    if (client.ip ~ warmuper_ip && req.http.Cache-Control ~ "no-cache") {
        set req.hash_always_miss = true;
    }
}

My question is, although this is working, every time I use this is it clearing cache and then add my urls? Because I am newbie and I don't want to clear Varnish every time I run this script. I just want to cache my links without affection previous cached links.

标签: varnishvarnish-vcl

解决方案


$req.http.Cache-Control ~ "no-cache"我认为您从后端检索的内容不会被缓存。内容只是被获取和交付,但不会存储在缓存中。


推荐阅读