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