Skip to content

Commit

Permalink
move
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshka committed Dec 7, 2023
1 parent 79a5572 commit d95d9c8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/sdk/src/contract/edition-v2/read/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
32 changes: 32 additions & 0 deletions packages/sdk/src/utils/cache-singleton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export class CacheSingleton {
private static instance: CacheSingleton
private cache: Map<string, any>

private constructor() {
this.cache = new Map<string, any>()
}

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)
}
}
14 changes: 14 additions & 0 deletions packages/sdk/src/utils/cache-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CacheSingleton } from './cache-singleton'

export class CacheUtils {
private static cache = CacheSingleton.getInstance()

public static async getOrSetCache<T>(key: string, fetchData: () => Promise<T>): Promise<T> {
let data = this.cache.get(key)
if (!data) {
data = await fetchData()
this.cache.set(key, data)
}
return data
}
}

0 comments on commit d95d9c8

Please sign in to comment.