在Varnish中的缓存对象中使用ESI标签

时间:2012-07-09 13:40:53

标签: varnish esi

我一直在这里关注指南: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(Cache-Control:max-age = 1,私有):

    <%= Time.now %>

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

    第一次请求:

    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
    

    我的清漆版本是这个(在Mac OS X上运行,带有Varnish的版本 Homebrew repo):

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

0 个答案:

没有答案