1CURLOPT_DNS_CACHE_TIMEOUT(3)curl_easy_setopt optionsCURLOPT_DNS_CACHE_TIMEOUT(3)
2
3
4

NAME

6       CURLOPT_DNS_CACHE_TIMEOUT - life-time for DNS cache entries
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_CACHE_TIMEOUT, long
12       age);
13

DESCRIPTION

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

DEFAULT

32       60
33

PROTOCOLS

35       All
36

EXAMPLE

38       CURL *curl = curl_easy_init();
39       if(curl) {
40         curl_easy_setopt(curl, CURLOPT_URL, "https://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

AVAILABILITY

55       Always
56

RETURN VALUE

58       Returns CURLE_OK
59

SEE ALSO

61       CURLOPT_DNS_USE_GLOBAL_CACHE(3),  CURLOPT_DNS_SERVERS(3),   CURLOPT_RE‐
62       SOLVE(3),
63
64
65
66libcurl 7.79.1                September 08, 2021  CURLOPT_DNS_CACHE_TIMEOUT(3)
Impressum