diff --git a/lib/utils/ens-cache.js b/lib/utils/ens-cache.js --- a/lib/utils/ens-cache.js +++ b/lib/utils/ens-cache.js @@ -12,13 +12,13 @@ type ENSNameQueryCacheEntry = { // We normalize ETH addresses to lowercase characters +normalizedETHAddress: string, - +cacheInsertionTime: number, + +expirationTime: number, // We normalize ENS names using eth-ens-namehash +normalizedENSName: ?string | Promise, }; type ENSAddressQueryCacheEntry = { +normalizedENSName: string, - +cacheInsertionTime: number, + +expirationTime: number, +normalizedETHAddress: ?string | Promise, }; @@ -85,7 +85,7 @@ this.nameQueryCache.set(normalizedETHAddress, { normalizedETHAddress, - cacheInsertionTime: Date.now(), + expirationTime: Date.now() + cacheTimeout, normalizedENSName: fetchENSNamePromise, }); @@ -93,7 +93,7 @@ const normalizedENSName = await fetchENSNamePromise; this.nameQueryCache.set(normalizedETHAddress, { normalizedETHAddress, - cacheInsertionTime: Date.now(), + expirationTime: Date.now() + cacheTimeout, normalizedENSName, }); return normalizedENSName; @@ -108,8 +108,8 @@ return undefined; } - const { cacheInsertionTime } = cacheResult; - if (cacheInsertionTime + cacheTimeout <= Date.now()) { + const { expirationTime } = cacheResult; + if (expirationTime <= Date.now()) { this.nameQueryCache.delete(normalizedETHAddress); return undefined; } @@ -152,7 +152,7 @@ this.addressQueryCache.set(normalizedENSName, { normalizedENSName, - cacheInsertionTime: Date.now(), + expirationTime: Date.now() + cacheTimeout, normalizedETHAddress: fetchETHAddressPromise, }); @@ -160,7 +160,7 @@ const normalizedETHAddress = await fetchETHAddressPromise; this.addressQueryCache.set(normalizedENSName, { normalizedENSName, - cacheInsertionTime: Date.now(), + expirationTime: Date.now() + cacheTimeout, normalizedETHAddress, }); return normalizedETHAddress; @@ -178,8 +178,8 @@ return undefined; } - const { cacheInsertionTime } = cacheResult; - if (cacheInsertionTime + cacheTimeout <= Date.now()) { + const { expirationTime } = cacheResult; + if (expirationTime <= Date.now()) { this.addressQueryCache.delete(normalizedENSName); return undefined; }