python mechanize的缓存功能与普通浏览器缓存功能一样吗?
在它的文档中提到:“可以通过使用 Mechanize.OpenerDirector
来避免这种缓存行为。”那么,这个缓存会影响下一次请求同一个页面吗?
1 个回答
1
我觉得文档中提到的“缓存”是指可以随意跳转的响应,而不是像浏览器那样的缓存功能。举个例子:
total_nr_bytes = len(response.get_data())
assert len(response.read()) == total_nr_bytes
assert len(response.read()) == 0 # we've already read the data
response.seek(0)
assert len(response.read()) == total_nr_bytes
它是在你调用 .read()
这个方法后,把数据缓存到 Python 对象里,而不是在你再次请求同一页面时缓存页面本身。
简单来说:不会影响你下次请求同一页面的结果。