urllib2.urlopen() 是否缓存东西? [英] Does urllib2.urlopen() cache stuff?

查看:35
本文介绍了urllib2.urlopen() 是否缓存东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们在python文档中没有提到这一点.最近我正在测试一个网站,只是使用 urllib2.urlopen() 刷新网站以提取某些内容,我注意到有时当我更新网站时 urllib2.urlopen() 似乎没有获得新添加的内容.所以我想知道它是否在某处缓存了东西,对吧?

They didn't mention this in python documentation. And recently I'm testing a website simply refreshing the site using urllib2.urlopen() to extract certain content, I notice sometimes when I update the site urllib2.urlopen() seems not get the newly added content. So I wonder it does cache stuff somewhere, right?

推荐答案

所以我想知道它会在某处缓存东西,对吗?

So I wonder it does cache stuff somewhere, right?

它没有.

如果您没有看到新数据,这可能有很多原因.大多数大型网络服务出于性能原因使用服务器端缓存,例如使用 Varnish 和 Squid 等缓存代理或应用程序级缓存.

If you don't see new data, this could have many reasons. Most bigger web services use server-side caching for performance reasons, for example using caching proxies like Varnish and Squid or application-level caching.

如果问题是由服务器端缓存引起的,通常没有办法强制服务器给你最新的数据.

If the problem is caused by server-side caching, usally there's no way to force the server to give you the latest data.

对于像 squid 这样的缓存代理,情况就不同了.通常,squid 会在 HTTP 响应中添加一些额外的标头(response().info().headers).

For caching proxies like squid, things are different. Usually, squid adds some additional headers to the HTTP response (response().info().headers).

如果您看到名为 X-CacheX-Cache-Lookup 的标头字段,这意味着您没有直接连接到远程服务器,而是通过透明代理.

If you see a header field called X-Cache or X-Cache-Lookup, this means that you aren't connected to the remote server directly, but through a transparent proxy.

如果您有类似:X-Cache: HIT from proxy.domain.tld,这意味着您得到的响应已被缓存.相反的是X-Cache MISS from proxy.domain.tld,表示响应是新鲜的.

If you have something like: X-Cache: HIT from proxy.domain.tld, this means that the response you got is cached. The opposite is X-Cache MISS from proxy.domain.tld, which means that the response is fresh.

这篇关于urllib2.urlopen() 是否缓存东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆