UNPKG

@acuris/leprechaun-cache

Version:

Caching library that supports double checked caching and stale returns to avoid stampede and slow responses

26 lines (25 loc) 847 B
import { Cacheable, LeprechaunCacheOptions } from './types'; export declare class LeprechaunCache<T extends Cacheable = Cacheable> { private softTtlMs; private hardTtlMs; private lockTtlMs; private waitTimeMs; private returnStale; private spinWaitCount; private cacheStore; private spinMs; private inProgress; private onMiss; private keyPrefix; private onBackgroundError; constructor({ keyPrefix, softTtlMs, hardTtlMs, lockTtlMs, waitTimeMs, waitForUnlockMs, cacheStore, spinMs, returnStale, onMiss, onBackgroundError }: LeprechaunCacheOptions<T>); clear(key: string): Promise<boolean>; get(key: string): Promise<T>; refresh(key: string): Promise<T>; private doGet; private race; private spinLock; private updateCache; private unlock; private setAndUnlock; }