improve memoize caching

This commit is contained in:
Josh Harvey 2017-12-31 10:13:22 +01:00
parent 70438b9796
commit 4214971cea
2 changed files with 15 additions and 6 deletions

View file

@ -40,7 +40,7 @@ function fetchWallet (settings, cryptoCode) {
const lastBalance = {}
function balance (settings, cryptoCode) {
function _balance (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.balance(r.account, cryptoCode))
.then(balance => ({balance, timestamp: Date.now()}))
@ -151,8 +151,13 @@ function cryptoNetwork (settings, cryptoCode) {
return wallet.cryptoNetwork(account, cryptoCode)
}
const balance = mem(_balance, {
maxAge: FETCH_INTERVAL,
cacheKey: (settings, cryptoCode) => cryptoCode
})
module.exports = {
balance: mem(balance, {maxAge: FETCH_INTERVAL}),
balance,
sendCoins,
newAddress,
getStatus,