用varnish缓存PROPFIND请求

时间:2014-08-04 13:41:40

标签: caching varnish caldav

我将在我的caldav服务器前使用清漆。所有客户定期提出PROPFIND和OPTIONS请求。我可以使用varnish缓存PROPFIND / OPTIONS请求的响应吗?

我将在PUT请求后清除缓存。以下配置不起作用。我没有缓存命中...

vcl 4.0;

import std;

backend baikal {
    .host = "127.0.0.1";
    .port = "6083";
}

acl upstream_proxy {
    "127.0.0.1";
}

sub vcl_recv {
    # purge cache for baikal.example.com after put request
    if (req.method == "PUT" && req.http.host == "baikal.example.com") {
        ban("req.http.host == " + req.http.Host);
    }

    # Set the X-Forwarded-For header so the backend can see the original
    # IP address. If one is already set by an upstream proxy, we'll just re-use that.
    if (client.ip ~ upstream_proxy && req.http.X-Forwarded-For) {
        set req.http.X-Forwarded-For = req.http.X-Forwarded-For;
    } else {
        set req.http.X-Forwarded-For = regsub(client.ip, ":.*", "");
    }

    std.log("ip:" + req.http.x-forwarded-for);

    if (req.http.host == "baikal.example.com") {
        set req.backend_hint = baikal;
    }

    if (req.method == "PROPFIND" && req.http.host == "baikal.example.com") {
        return(hash);
    }

    return(hash);
}

sub vcl_backend_response {
    if (beresp.http.method == "PROPFIND" ) {
        unset beresp.http.pragma;
        unset beresp.http.cache-control;
        unset beresp.http.expires;
        set beresp.ttl = 1 w;
        set beresp.http.magicmarker = "1";
    }
}


sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    # 
    # You can do accounting or modifying the final object here.
    if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
        set resp.http.X-Cache-Hits = obj.hits;
    } else {
        set resp.http.X-Cache = "MISS";
    }
}

0 个答案:

没有答案