From: Brian Aker Date: Mon, 19 Nov 2007 17:47:20 +0000 (-0800) Subject: Added MEMCACHED_BEHAVIOR_CACHE_LOOKUPS flag (you can now avoid multiple DNS X-Git-Tag: 0.10~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8d0cd77fc7bafd1f353bc7c50910b751766f931a;p=awesomized%2Flibmemcached Added MEMCACHED_BEHAVIOR_CACHE_LOOKUPS flag (you can now avoid multiple DNS lookups). --- diff --git a/ChangeLog b/ChangeLog index 904dd8a5..26c4b141 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.10 * Added append binary test. + * Added MEMCACHED_BEHAVIOR_CACHE_LOOKUPS behavior so that you can save on + multiple DNS lookups. 0.9 Thu Nov 15 07:44:00 PST 2007 * fix for when no servers are definied. diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index 296988e5..4d7d1140 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -51,6 +51,9 @@ environments). Makes the default hashing algorithm for keys use MD5. The value can be set to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_KETAMA. The behavior for all hashes but MEMCACHED_HASH_DEFAULT is identitical to the Java driver written by Dustin Sallings. +=item MEMCACHED_BEHAVIOR_CACHE_LOOKUPS + +Memcached can cache named lookups so that DNS lookups are made only once. =back diff --git a/include/memcached.h b/include/memcached.h index 316f1f3f..53b51ea0 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -73,6 +73,7 @@ typedef enum { MEMCACHED_BEHAVIOR_KETAMA, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, + MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, } memcached_behavior; typedef enum { diff --git a/lib/common.h b/lib/common.h index 3b8946a1..1e564cf5 100644 --- a/lib/common.h +++ b/lib/common.h @@ -43,6 +43,7 @@ typedef enum { MEM_USE_MD5= (1 << 3), MEM_USE_KETAMA= (1 << 4), MEM_USE_CRC= (1 << 5), + MEM_USE_CACHE_LOOKUPS= (1 << 6), } memcached_flags; /* Hashing algo */ diff --git a/lib/memcached_behavior.c b/lib/memcached_behavior.c index fb04d722..67a52fa8 100644 --- a/lib/memcached_behavior.c +++ b/lib/memcached_behavior.c @@ -35,6 +35,9 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_HASH: ptr->hash= *(memcached_hash *)(data); break; + case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS: + set_behavior_flag(ptr, MEM_USE_CACHE_LOOKUPS, data); + break; case MEMCACHED_BEHAVIOR_KETAMA: set_behavior_flag(ptr, MEM_USE_KETAMA, data); break; @@ -64,6 +67,9 @@ unsigned long long memcached_behavior_get(memcached_st *ptr, switch (flag) { + case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS: + temp_flag= MEM_USE_CACHE_LOOKUPS; + break; case MEMCACHED_BEHAVIOR_NO_BLOCK: temp_flag= MEM_NO_BLOCK; break; diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index 0c256b71..fffd2b88 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -72,7 +72,12 @@ static memcached_return udp_connect(memcached_st *ptr, unsigned int server_key) /* Old connection junk still is in the structure */ WATCHPOINT_ASSERT(ptr->hosts[server_key].stack_responses == 0); - if (ptr->hosts[server_key].sockaddr_inited == MEMCACHED_NOT_ALLOCATED) + /* + If we have not allocated the hosts object. + Or if the cache has not been set. + */ + if (ptr->hosts[server_key].sockaddr_inited == MEMCACHED_NOT_ALLOCATED || + (!(ptr->flags & MEM_USE_CACHE_LOOKUPS))) { memcached_return rc;