diff --git a/src/util.ts b/src/util.ts index 54d0621..3eb064d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -39,21 +39,22 @@ export default { }, getMinecraftHead(player: DynmapPlayer | string, size: string): Promise { - const account = typeof player === 'string' ? player : player.account; + const account = typeof player === 'string' ? player : player.account, + cacheKey = `${account}-${size}`; - if(headCache.has(account)) { - return Promise.resolve(headCache.get(account) as HTMLImageElement); + if(headCache.has(cacheKey)) { + return Promise.resolve(headCache.get(cacheKey) as HTMLImageElement); } - if(headUnresolvedCache.has(account)) { - return headUnresolvedCache.get(account) as Promise; + if(headUnresolvedCache.has(cacheKey)) { + return headUnresolvedCache.get(cacheKey) as Promise; } const promise = new Promise((resolve, reject) => { const faceImage = new Image(); faceImage.onload = function() { - headCache.set(account, faceImage); + headCache.set(cacheKey, faceImage); resolve(faceImage); }; @@ -64,9 +65,9 @@ export default { const src = (size === 'body') ? `faces/body/${account}.png` :`faces/${size}x${size}/${account}.png`; faceImage.src = this.concatURL(window.config.url.markers, src); - }).finally(() => headUnresolvedCache.delete(account)) as Promise; + }).finally(() => headUnresolvedCache.delete(cacheKey)) as Promise; - headUnresolvedCache.set(account, promise); + headUnresolvedCache.set(cacheKey, promise); return promise; },