memcached-multiplex
combine concurrent gets for the same keys into one get/multiget to the server
// first you need memcached. (or something that implements the methods get and getMulti)var Memcached = ;var multi = ; var getter = ; // all of these callsgetter getter getter // make only one call to the memcache server // get a,bgetter; // get c but not b because im alredy fetching bgetter; // no call is made im already requesting the keys im searching for.getter; // triggers 2 "getMulti" on the client driver.// one for keys ['a','b'] and one for just key ['c']
multi = require('memcached-multiplex')(new Memcached(hosts));
- this module exports a function
- if you call this function with a memcached client you will get an object with getter methods
.get(key,cb)
gets the key
.getMulti([key, key2],cb)
get multiple keys
.stats
-
stats is an object
-
it has stats that help you determine how well you are multiplexing
-
get
- keys , how many single keys were requested from the memcached server
- calls, how many keys were requested by calls to the function
-
multi
- keys, how many keys were requested from the memcached server
- requested, how many keys were requested by calls to getMulti
- calls, how many calls to getMulti
- made, how many calls to get multi resulted in fetching keys from the memcached server
get:keys:0calls:0 multi:keys:0requested:0calls:0made:0
rant! if you use node you should not make multiple concurrent gets for the same external resources. this applies to databases web services whatever.