DNS Caching in Go
In the development of a test crawler, a common inquiry arises: does Go (golang) implement caching mechanisms for DNS queries?
Upon examining the dnsclient package, no explicit mention of caching is discernible. However, this functionality is often crucial for crawler optimization, minimizing extra DNS queries.
Answer:
The default implementation of Go (1.4 ) does not include built-in DNS caching.
Alternative Caching Mechanisms:
Example:
<code class="go">http.DefaultClient.Transport = &http.Transport{ MaxIdleConnsPerHost: 64, Dial: func(network string, address string) (net.Conn, error) { separator := strings.LastIndex(address, ":") ip, _ := dnscache.FetchString(address[:separator]) return net.Dial("tcp", ip+address[separator:]) }, }</code>
The above is the detailed content of Does Go (golang) Include Built-in DNS Caching?. For more information, please follow other related articles on the PHP Chinese website!