Does urllib2.urlopen() cache stuff?

后端 未结 5 1732
渐次进展
渐次进展 2020-12-17 16:35

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 notic

5条回答
  •  情歌与酒
    2020-12-17 17:00

    So I wonder it does cache stuff somewhere, right?

    It doesn't.

    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.


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

    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.

    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.

提交回复
热议问题