From 74c078392c46405a8432309c8672dc09642956d6 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Tue, 16 Feb 2021 18:40:36 -0600 Subject: change profileCache to use clones --- src/cleaners/skyblock/collections.ts | 2 +- src/hypixelCached.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts index 3b1a178..a3e1fb3 100644 --- a/src/cleaners/skyblock/collections.ts +++ b/src/cleaners/skyblock/collections.ts @@ -1,4 +1,4 @@ -import { cleanItemId, cleanItemNames, hypixelItemNames } from "./itemId" +import { cleanItemId, hypixelItemNames } from "./itemId" const COLLECTIONS = { 'farming': [ diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index ae544a2..e311fe6 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -10,6 +10,10 @@ import { undashUuid } from './util' import { CleanProfile, CleanFullProfile, CleanBasicProfile } from './cleaners/skyblock/profile' +// TODO: put this somewhere else +const debug = false + + // cache usernames for 4 hours const usernameCache = new NodeCache({ stdTTL: 60 * 60 * 4, @@ -32,7 +36,7 @@ const playerCache = new NodeCache({ const profileCache = new NodeCache({ stdTTL: 30, checkperiod: 10, - useClones: false, + useClones: true, }) const profilesCache = new NodeCache({ @@ -79,6 +83,7 @@ export async function uuidFromUser(user: string): Promise { */ export async function usernameFromUser(user: string): Promise { if (usernameCache.has(undashUuid(user))) { + if (debug) console.log('Cache hit! usernameFromUser', user) return usernameCache.get(undashUuid(user)) } @@ -93,6 +98,7 @@ export async function fetchPlayer(user: string): Promise { const playerUuid = await uuidFromUser(user) if (playerCache.has(playerUuid)) { + if (debug) console.log('Cache hit! fetchPlayer', playerUuid) return playerCache.get(playerUuid) } @@ -112,6 +118,7 @@ export async function fetchPlayer(user: string): Promise { export async function fetchSkyblockProfiles(playerUuid: string): Promise { if (profilesCache.has(playerUuid)) { + if (debug) console.log('Cache hit! fetchSkyblockProfiles', playerUuid) return profilesCache.get(playerUuid) } @@ -157,6 +164,7 @@ export async function fetchSkyblockProfiles(playerUuid: string): Promise { const playerUuid = await uuidFromUser(user) if (basicProfilesCache.has(playerUuid)) { + if (debug) console.log('Cache hit! fetchBasicProfiles', playerUuid) return basicProfilesCache.get(playerUuid) } const player = await fetchPlayer(playerUuid) @@ -202,6 +210,7 @@ export async function fetchProfile(user: string, profile: string): Promise