@blocklet/payment-react
Version:
Reusable react components for payment kit v2
34 lines (26 loc) • 728 B
text/typescript
type CacheItem = {
promise: Promise<any> | null;
};
class GlobalCacheManager {
private static instance: GlobalCacheManager;
private cacheMap: Map<string, CacheItem>;
private constructor() {
this.cacheMap = new Map();
}
static getInstance() {
if (!GlobalCacheManager.instance) {
GlobalCacheManager.instance = new GlobalCacheManager();
}
return GlobalCacheManager.instance;
}
get(cacheKey: string): CacheItem | undefined {
return this.cacheMap.get(cacheKey);
}
set(cacheKey: string, item: CacheItem) {
this.cacheMap.set(cacheKey, item);
}
delete(cacheKey: string) {
this.cacheMap.delete(cacheKey);
}
}
export const globalCache = GlobalCacheManager.getInstance();