Files
api/packages/api-derive/src/util/cacheImpl.ts
T
Tarik Gul 241a1a3630 2025 (#6052)
* 2025

* change metadata script
2025-01-01 20:02:48 +02:00

31 lines
809 B
TypeScript

// Copyright 2017-2025 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DeriveCache } from './types.js';
const mapCache = new Map<string, any>();
export const deriveMapCache: DeriveCache = {
del: (key: string): void => {
mapCache.delete(key);
},
forEach: (cb: (key: string, value: any) => void): void => {
for (const [k, v] of mapCache.entries()) {
cb(k, v);
}
},
get: <T = any> (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
};