1CURLOPT_DNS_CACHE_TIMEOUT(3)curl_easy_setopt optionsCURLOPT_DNS_CACHE_TIMEOUT(3)
2
3
4
6 CURLOPT_DNS_CACHE_TIMEOUT - life-time for DNS cache entries
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_CACHE_TIMEOUT, long age);
12
14 Pass a long, this sets the timeout in seconds. Name resolves will be
15 kept in memory and used for this number of seconds. Set to zero to com‐
16 pletely disable caching, or set to -1 to make the cached entries remain
17 forever. By default, libcurl caches this info for 60 seconds.
18
19 The name resolve functions of various libc implementations do not re-
20 read name server information unless explicitly told so (for example, by
21 calling res_init(3)). This may cause libcurl to keep using the older
22 server even if DHCP has updated the server info, and this may look like
23 a DNS cache issue to the casual libcurl-app user.
24
25 Note that DNS entries have a "TTL" property but libcurl does not use
26 that. This DNS cache timeout is entirely speculative that a name will
27 resolve to the same address for a certain small amount of time into the
28 future.
29
31 60
32
34 All
35
37 CURL *curl = curl_easy_init();
38 if(curl) {
39 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
40
41 /* only reuse addresses for a short time */
42 curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, 2L);
43
44 ret = curl_easy_perform(curl);
45
46 /* in this second request, the cache will not be used if more than
47 two seconds have passed since the previous name resolve */
48 ret = curl_easy_perform(curl);
49
50 curl_easy_cleanup(curl);
51 }
52
54 Always
55
57 Returns CURLE_OK
58
60 CURLOPT_DNS_USE_GLOBAL_CACHE(3), CURLOPT_DNS_SERVERS(3), CURLOPT_RE‐
61 SOLVE(3),
62
63
64
65libcurl 7.85.0 May 17, 2022 CURLOPT_DNS_CACHE_TIMEOUT(3)