improve memoize caching
This commit is contained in:
parent
70438b9796
commit
4214971cea
2 changed files with 15 additions and 6 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue