CURLOPT_DN...OBAL_CACHE(3)

πŸ’– NAME πŸ’–

CURLOPT_DNS_USE_GLOBAL_CACHE β€” the global DNS cache situation, aka the fossil you should absolutely not be touching πŸ’€

(this one lives in the Library Functions Manual, bestie β€” hi, welcome, come sit with me ✨)


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_USE_GLOBAL_CACHE,
                          long enable);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so first things first, and I need you to hear me on this: it has no function since 7.62.0. Do not use. Like, at all. It's giving haunted artifact in the attic. πŸ™ˆ

You pass it a long. Back in the day, if the enable value was 1, it told curl to use a global DNS cache that survives between easy handle creations and deletions. Cute in theory! But nope β€” this is not thread-safe and it uses a global variable, which is exactly the kind of chaos that makes your future self cry at 3am 😭

So if you actually want to share a DNS cache between transfers, the correct slay is CURLOPT_SHARE(3) and curl_share_init(3). Use those. They ate. πŸ‘‘


πŸŽ€ DEFAULT πŸŽ€

0


🌈 PROTOCOLS 🌈

This functionality affects all supported protocols β€” every single one, no cap ✨


🧚 EXAMPLE 🧚

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
    /* switch off the use of a global, thread-unsafe, cache */
    curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE, 0L);
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

See how they set it to 0L? That's the move β€” turning the thread-unsafe global cache off. Iconic behaviour, no notes πŸ’…


πŸ’€ DEPRECATED πŸ’€

Deprecated since 7.11.1. Functionality removed in 7.62.0.

Yeah. It's been deprecated longer than some of us have been alive, and the whole feature got yeeted in 7.62.0. It's literally a ghost option now πŸ‘»


⭐ AVAILABILITY ⭐

Added in curl 7.9.3 β€” a true elder of the library 🫢


πŸ’œ RETURN VALUE πŸ’œ

curl_easy_setopt(3) returns a CURLcode indicating success or error.

  • CURLE_OK (0) means everything was OK ✨
  • non-zero means an error occurred β€” check out libcurl-errors(3) for the deets

πŸ”₯ SEE ALSO πŸ”₯


That's the whole vibe check, bestie β€” this page is from libcurl, dated 2026-10-12. Stay safe, don't use the global cache, and go touch some shared memory instead πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from