简体   繁体   English

如何将CURLOPT_DNS_CACHE_TIMEOUT与共享DNS缓存一起使用

[英]How to use CURLOPT_DNS_CACHE_TIMEOUT with shared DNS cache

I'm using my own pool of CURL easy handles reused in multi threaded application - the goal is to reuse TCP connections and DNS lookups. 我正在使用我自己的CURL简易句柄池在多线程应用程序中重用 - 目标是重用TCP连接和DNS查找。 Every time a handle is returned to the pool curl_easy_reset is called on that handle. 每次将句柄返回到池时, curl_easy_reset在该句柄上调用curl_easy_reset

At the moment my implementation uses separate local DNS cache for every CURL easy handle. 目前,我的实现为每个CURL简易句柄使用单独的本地DNS缓存。 I'm playing with CURL shared interface and shared DNS cache and it seems to work pretty well but I don't understand what is the correct way to set DNS cache timeout? 我正在玩CURL共享接口和共享DNS缓存,它似乎工作得很好,但我不明白什么是设置DNS缓存超时的正确方法?

DNS cache timeout is set on CURL easy handle but the cache is shared. DNS缓存超时在CURL easy handle上设置,但缓存是共享的。 Do I need to set the timeout every time I get a handle from the pool (because of reset called previously) or is cache timeout set only once and remembered until I change it? 我是否需要在每次从池中获取句柄时设置超时(因为先前调用了重置)或者是否只设置了一次缓存超时并记住,直到我更改它为止?

The timeout value is actually stored and used per easy handle. 实际存储和使用超时值的每个简易句柄。 Each easy handle thus has its own timeout value, even when the DNS cache is shared. 因此,每个简易句柄都有自己的超时值,即使共享DNS缓存也是如此。 Each easy handle will thus evict a too old entry and re-resolve a name again according to its own value. 因此,每个简单句柄将逐出旧条目并根据其自身值再次重新解析名称。

When you set the timeout value for an easy handle, that timeout value will "stick" and be used until you set it again to something else. 当您为一个简单的句柄设置超时值时,该超时值将“粘住”并被使用,直到您再次将其设置为其他值。 (Like all other options.) (像所有其他选项一样。)

Calling curl_easy_reset() on the handle will of course reset the timeout value for the handle back to its internal default. 在句柄上调用curl_easy_reset()当然会将句柄的超时值重置为其内部默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM