UNPKG

layered-loader

Version:

Data loader with support for caching and fallback data sources

35 lines (34 loc) 1.53 kB
import type { HitStatisticsRecord } from 'toad-cache'; import type { CommonCacheConfiguration } from '../types/DataSources'; import type { GetManyResult, SynchronousGroupCache } from '../types/SyncDataSources'; type CacheTypeId = 'lru-map' | 'fifo-map' | 'lru-object' | 'fifo-object' | 'lru-object-statistics'; export interface InMemoryGroupCacheConfiguration extends CommonCacheConfiguration { cacheId?: string; globalStatisticsRecord?: HitStatisticsRecord; cacheType?: CacheTypeId; groupCacheType?: CacheTypeId; groupTtlInMsecs?: number; maxGroups?: number; maxItemsPerGroup?: number; } export declare class InMemoryGroupCache<T> implements SynchronousGroupCache<T> { private readonly groups; private readonly maxItemsPerGroup; name: string; private readonly ttlInMsecs; readonly ttlLeftBeforeRefreshInMsecs?: number; private readonly cacheConstructor; private readonly groupCacheConstructor; private readonly cacheId?; private readonly globalStatisticsRecord?; constructor(config: InMemoryGroupCacheConfiguration); private resolveGroup; deleteGroup(group: string): void; getFromGroup(key: string, groupId: string): T | null | undefined; getManyFromGroup(keys: string[], group: string): GetManyResult<T>; setForGroup(key: string, value: T | null, groupId: string): void; deleteFromGroup(key: string, groupId: string): void; clear(): void; getExpirationTimeFromGroup(key: string, groupId: string): number | undefined; } export {};