diff --git a/packages/sdk/src/contract/edition-v2/read/helpers.ts b/packages/sdk/src/contract/edition-v2/read/helpers.ts index e4d723a8..862ed9a5 100644 --- a/packages/sdk/src/contract/edition-v2/read/helpers.ts +++ b/packages/sdk/src/contract/edition-v2/read/helpers.ts @@ -3,8 +3,8 @@ import { nowUnixTimestamp } from '../../../utils/helpers' import { SOUND_EDITION_V2_ABI } from '../abi/sound-edition-v2' import { SUPER_MINTER_V1, SUPER_MINTER_V1_ADDRESS } from '../abi/super-minter-v1' import { SUPER_MINTER_V1_1, SUPER_MINTER_V1_1_ADDRESS } from '../abi/super-minter-v1_1' -import { CacheUtils } from '../cache/cache-utils' import type { GetEditionContractInfoReturnType } from './info' +import { CacheUtils } from '../../../utils/cache-utils' export function getTierCurrentMaxMintable( tierInfo: Pick< diff --git a/packages/sdk/src/utils/cache-singleton.ts b/packages/sdk/src/utils/cache-singleton.ts new file mode 100644 index 00000000..32d9b33a --- /dev/null +++ b/packages/sdk/src/utils/cache-singleton.ts @@ -0,0 +1,32 @@ +export class CacheSingleton { + private static instance: CacheSingleton + private cache: Map + + private constructor() { + this.cache = new Map() + } + + public static getInstance(): CacheSingleton { + if (!CacheSingleton.instance) { + CacheSingleton.instance = new CacheSingleton() + } + return CacheSingleton.instance + } + + public set(key: string, value: any): void { + this.cache.set(key, value) + } + + public get(key: string): any { + return this.cache.get(key) + } + + // Optionally, you can add methods to clear the cache or check if a key exists + public clear(): void { + this.cache.clear() + } + + public has(key: string): boolean { + return this.cache.has(key) + } +} diff --git a/packages/sdk/src/utils/cache-utils.ts b/packages/sdk/src/utils/cache-utils.ts new file mode 100644 index 00000000..2133ddfb --- /dev/null +++ b/packages/sdk/src/utils/cache-utils.ts @@ -0,0 +1,14 @@ +import { CacheSingleton } from './cache-singleton' + +export class CacheUtils { + private static cache = CacheSingleton.getInstance() + + public static async getOrSetCache(key: string, fetchData: () => Promise): Promise { + let data = this.cache.get(key) + if (!data) { + data = await fetchData() + this.cache.set(key, data) + } + return data + } +}