简体   繁体   English

清漆缓存 - 缓存页面的时间长度?

[英]Varnish cache - how long the pages are cached?

I have a doubt regarding the working of vanish cache. 我对消失缓存的工作有疑问。 I installed the varnish cache with my apache web sever and configured the same correctly, so that I can access web pages through varnish cache. 我用我的apache web服务器安装了varnish缓存并正确配置了相同的内容,以便我可以通过varnish缓存访问网页。

The question is here, that I have created a 'test.php' page and this can be accessed through browser. 问题在于,我创建了一个'test.php'页面,可以通过浏览器访问。 I have changed the content of the page and immediately after again accessed the same page through browser. 我已经更改了页面的内容,并在通过浏览器再次访问同一页面后立即进行了更改。 The second time it was showing the changed content. 第二次显示更改的内容。 Why it is so? 为什么会这样? Up to my knowledge, the second time also it should show the old content (?); 据我所知,第二次也应该显示旧内容(?); because varnish cache will retain contents of web pages for a shot interval. 因为清漆缓存将保留一个镜头间隔的网页内容。 Is there any settings that I need to change? 我需要更改任何设置吗? Please advice. 请指教。

Thank You. 谢谢。

If your seeing the latest contents each time you refresh then you haven't set varnish up properly. 如果您每次刷新时都看到最新内容,那么您没有正确设置清漆。

Varnish should sit on a different port to Apache so make sure your visiting test.php on the varnish port. Varnish应该位于Apache的不同端口上,因此请确保您在varnish端口上访问test.php。

You can put this in your config to see if it's caching.. 你可以把它放在你的配置中,看看它是否正在缓存..

sub vcl_deliver {
    # Add a header to indicate a cache HIT/MISS
    if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
    } else {
        set resp.http.X-Cache = "MISS";
    }
    return (deliver);
}

If you see the X-Cache header then you know it's at least running through varnish. 如果你看到X-Cache标题,那么你知道它至少是通过清漆运行的。

The http headers you're setting in your pages play a great role to decide whether they will be cached or not. 您在页面中设置的http标头可以决定是否缓存它们。 Read the varnish documentation about this 阅读关于此的清漆文档

This thread looks old. 这个帖子看起来很旧。 But this value can be found in the vanish config set the value for VARNISH_TTL 但是这个值可以在消失的配置中找到VARNISH_TTL的值

# # Default TTL used when the backend does not specify one
VARNISH_TTL= 120

The default is 120 seconds I am sure you can change it from that point 默认为120秒我相信你可以从那一点改变它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM