CURLOPT_DNS_CACHE_TIMEOUT.3 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. .\" generated by cd2nroff 0.1 from CURLOPT_DNS_CACHE_TIMEOUT.md
  2. .TH CURLOPT_DNS_CACHE_TIMEOUT 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_DNS_CACHE_TIMEOUT \- life\-time for DNS cache entries
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_CACHE_TIMEOUT, long age);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a long, this sets the timeout in seconds. Name resolve results are kept
  12. in memory and used for this number of seconds. Set to zero to completely
  13. disable caching, or set to \-1 to make the cached entries remain forever. By
  14. default, libcurl caches this info for 60 seconds.
  15. We recommend users not to tamper with this option unless strictly necessary.
  16. If you do, be careful of using large values that can make the cache size grow
  17. significantly if many different hostnames are used within that timeout period.
  18. The name resolve functions of various libc implementations do not re\-read name
  19. server information unless explicitly told so (for example, by calling
  20. \fIres_init(3)\fP). This may cause libcurl to keep using the older server even
  21. if DHCP has updated the server info, and this may look like a DNS cache issue
  22. to the casual libcurl\-app user.
  23. DNS entries have a "TTL" property but libcurl does not use that. This DNS
  24. cache timeout is entirely speculative that a name resolves to the same address
  25. for a small amount of time into the future.
  26. Since version 8.1.0, libcurl prunes entries from the DNS cache if it exceeds
  27. 30,000 entries no matter which timeout value is used.
  28. .SH DEFAULT
  29. 60
  30. .SH PROTOCOLS
  31. This functionality affects all supported protocols
  32. .SH EXAMPLE
  33. .nf
  34. int main(void)
  35. {
  36. CURL *curl = curl_easy_init();
  37. if(curl) {
  38. CURLcode res;
  39. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
  40. /* only reuse addresses for a short time */
  41. curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, 2L);
  42. res = curl_easy_perform(curl);
  43. /* in this second request, the cache is not be used if more than
  44. two seconds have passed since the previous name resolve */
  45. res = curl_easy_perform(curl);
  46. curl_easy_cleanup(curl);
  47. }
  48. }
  49. .fi
  50. .SH AVAILABILITY
  51. Added in curl 7.9.3
  52. .SH RETURN VALUE
  53. Returns CURLE_OK
  54. .SH SEE ALSO
  55. .BR CURLOPT_CONNECTTIMEOUT_MS (3),
  56. .BR CURLOPT_DNS_SERVERS (3),
  57. .BR CURLOPT_DNS_USE_GLOBAL_CACHE (3),
  58. .BR CURLOPT_MAXAGE_CONN (3),
  59. .BR CURLOPT_RESOLVE (3)