// Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { DeriveCache } from './types'; const mapCache = new Map(); export const deriveMapCache: DeriveCache = { del: (key: string): void => { mapCache.delete(key); }, forEach: (cb: (key: string, value: any) => void): void => { const entries = mapCache.entries(); for (const entry in entries) { cb(entry[0], entry[1]); } }, get: (key: string): T | undefined => { return mapCache.get(key) as T; }, set: (key: string, value: any): void => { mapCache.set(key, value); } }; export const deriveNoopCache: DeriveCache = { del: (): void => undefined, forEach: () => undefined, get: (): undefined => undefined, set: (_: string, value: unknown): unknown => value };