CURLOPT_DNS_CACHE_TIMEOUT
: controls the TTL of a DNS cache entry. The default is 60s. Use -1 to keep the entry forever.CURLOPT_RESOLVE
: pre-populate the DNS cache manually.CURLOPT_DNS_SERVERS
: use alternate DNS servers (instead of system default ones). Warning: works only with c-ares (and it requires c-ares version >= 1.7.4),CURLOPT_DNS_USE_GLOBAL_CACHE
: cache DNS queries between easy handles. Warning: this is not thread-safe and documented as deprecated. Use the share interface instead (see below).
Use CURLINFO_NAMELOOKUP_TIME
to obtain the name resolving time post-transfer, for a given easy handle.
According to the share interface documentation:
When you use the multi interface, all easy handles added to the same multi handle will share DNS cache by default
libcurl internal structs documentation gives some more precisions:
multi->hostcache
points to the name cache. It is a hash table for looking up name to IP. The nodes have a limited life time in there and this cache is meant to reduce the time for when the same name is wanted within a short period of time.
From curl/lib/multi.c
we can confirm this hostcache
does not survive (of course) to the multi handle deletion:
CURLMcode curl_multi_cleanup(CURLM *multi_handle)
{
...
Curl_hash_destroy(multi->hostcache);
multi->hostcache = NULL;
...
}
In other words the multi interface DNS cache is NOT global [1].
The source code gives another precision vs. which DNS cache takes precedence:
for multi interface connections, we share DNS cache automatically if the easy handle's one is currently not set.
In other words the multi interface uses its own cache if the caller did not previously set a shared DNS cache on its easy handle via CURLOPT_SHARE
.
The CURL_LOCK_DATA_DNS
share option allows to cache DNS queries between easy handles.
See also this mailing list discussion:
[1]: which is BTW considered as evil by libcurl's TODO: Anything global is silly, and we already offer the share interface for the same functionality but done "right".