2

我一直在关注这里的指南:https ://www.varnish-cache.org/docs/trunk/tutorial/esi.html

到目前为止,我的项目中有两个页面:

  1. http://127.0.0.1:3001/(缓存控制:max-age=60,私有):

    <b>Cached:</b> <%= Time.now %> <br/>

    <b>ESI:</b> <esi:include src="/staticview" /> <br/>

  2. http://127.0.0.1:3001/staticview(缓存控制:max-age=1,私有):

    <%= Time.now %>

但是,每次我请求第一页时,它似乎也会缓存 60 秒的 ESI-include 结果,而不是每秒刷新一次。

第一个请求:

Cached: 2012-07-09 01:31:12 +0200
ESI: 2012-07-09 01:31:12 +0200

第二个请求(10 秒后):

Cached: 2012-07-09 01:31:12 +0200
ESI: 2012-07-09 01:31:12 +0200

第三个请求(大约一分钟后):

Cached: 2012-07-09 01:32:19 +0200
ESI: 2012-07-09 01:32:19 +0200

这是预期的行为吗?还是我误解了文档?

我的 VCL 配置如下所示:

backend default {
    .host = "127.0.0.1";
    .port = "3000";
}

sub vcl_recv {
    # Don't cache POST, PUT, or DELETE requests
    if (req.request == "POST" || req.request == "PUT" || req.request == "DELETE") {
        return(pass);
    }

    return(lookup);
}

sub vcl_fetch {
    # We want ESI
    set beresp.do_esi = true;

    if (beresp.http.Cache-Control ~ "max-age") {
        unset beresp.http.Set-Cookie;
        return(deliver);
    }

    # Do not deliver into cache otherwise.
    return(hit_for_pass);
}

sub vcl_deliver {
    if (obj.hits > 0) {
        set resp.http.X-Varnish-Cache = "HIT (" +obj.hits+ ")";
    } else {
        set resp.http.X-Varnish-Cache = "MISS";
    }
}

Varnish 使用以下参数运行:

varnishd -F -a 127.0.0.1:3001 -f config/varnish/development.vcl

我的 Varnish 版本是这样的(在 Mac OS X 上运行,使用来自 Homebrew repo 的 Varnish):

varnishd (varnish-3.0.2 revision 55e70a4)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2011 Varnish Software AS
4

0 回答 0