DNSpython 会使用缓存吗?

Will DNSpython use Cache?

我正在使用 DNSPython 库在我的脚本中获取 DNS 解析时间。我有一个关于缓存部分的查询,这个库是否单独使用缓存。我的要求是检查从端点解析 DNS 需要多少时间。

这是我现在用来获取解决时间的脚本部分,

resolver = dns.resolver.Resolver()
resolver.timeout = 1
resolver.lifetime = 1
return float("{0:.3f}".format(dns.resolver.query(url).response.time*1000))

如果 DNSPython 使用缓存,建议我刷新它的方法。如果可用,还建议我一些其他想法,以在不缓存的情况下获得 DNS 解析时间。

If DNSPython uses caching, suggest me a way to flush it. Also suggest me some other idea if available, to get DNS resolution time without caching.

dns.resolver.Cache.flush()

参见source here and the documentation here

大多数(几乎所有?)操作系统都有删除 DNS 缓存的命令行实用程序。在您的 python 代码中与 time for performance benchmarking. Perhaps also consider a timing decorator 结合使用以进行基准测试。