# asyncmemo Memoize asynchronous function calls. Combine multiple calls with the same argument so that the underlying function is only called once for that argument. Optionally cache the result for that argument. ## Install ``` npm install --save asyncmemo ``` ## Example ```js var asyncMemo = require('asyncmemo') var xhr = require('xhr') var get = asyncMemo(function (base, path, cb) { xhr.get(base + path, cb) }, 'http://localhost') get('/foo', function (err, resp) { console.log(err, resp) }) ``` ## API ### `asyncMemo([opts,] fn, [args...]): memo` - `opts.cache`: cache object, or false to disable cache - `opts.asString`: function to convert an argument to a string - `fn([args...], arg, cb(err, result))`: the asyncronous function to memoize - `args`: arguments to prepend to each call to `fn` - `memo(arg, cb(err, result))`: memoized asynchronous function - `memo.cache`: cache object, either `opts.cache` or a auto-created one A custom cache object can be passed using the `cache` option. This should have `has`, `get`, and `set` methods. If you want to be able to use memoize a key that is not a string or number, you can specify a `asString` function to convert the key argument to a string. ## Related - [async-memo](https://www.npmjs.com/package/async-memo) - [async-cache](https://www.npmjs.com/package/async-cache) - [memo-cache](https://www.npmjs.com/package/memo-cache) - [memoizeasync](https://www.npmjs.com/package/memoizeasync) - [thunky](https://github.com/mafintosh/thunky) - does the same except memoizes only one value ## License Copyright (c) 2016 Charles Lehner Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument. DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.