/** * In-memory TTL cache with amortized cleanup and per-cache stampede * protection. Module-level singletons (`getStaticCache`, * `getSemiStaticCache`, `getBalanceCache`, `getOrderbookCache`) back * the four tier-specific caches the SDK uses; all client instances * share them so a long-lived process never pays an unnecessary fetch * for the same key across instances. * * Cache keys are namespaced by `apiBaseUrl` so testnet and mainnet * clients do not collide on the same `(method, args)` pair. * * `withInstanceCache` never stores a `Result` whose `success` is false: * a transient failure must not be pinned for the tier's TTL. */ export declare class MemoryCache { /** TTL-expiry sweep runs once per this many `set` calls. */ static readonly CLEANUP_INTERVAL = 50; private store; /** Per-cache in-flight Promise map for stampede protection. */ private pending; private ttlMs; private maxSize; private writeCount; constructor(ttlSeconds: number, maxSize?: number); /** Update the TTL without replacing the cache instance. */ setTtl(ttlSeconds: number): void; /** Update the size cap without replacing the cache instance. */ setMaxSize(maxSize: number): void; get(key: string): T | null; set(key: string, value: any): void; clear(): void; /** Return the current entry count (live + still-stored expired). */ get size(): number; getPending(key: string): Promise | undefined; setPending(key: string, promise: Promise): void; deletePending(key: string): void; private trim; private cleanup; } export declare function getStaticCache(): MemoryCache; export declare function getSemiStaticCache(): MemoryCache; export declare function getBalanceCache(): MemoryCache; export declare function getOrderbookCache(): MemoryCache; /** * Override module-level cache TTLs from config. Mutates the underlying * singleton in place so any references already held by clients continue * to point at the live cache. Only TTLs that differ from the defaults * are applied; passing the default value is a no-op. */ export declare function configureCaches(config: { cacheTtlStatic?: number; cacheTtlSemiStatic?: number; cacheTtlBalance?: number; cacheTtlOrderbook?: number; }): void; /** * Clear all four module-level caches. Test suites should call this in * `beforeEach` / `afterEach` to avoid cross-test contamination — the * singletons live for the whole process. */ export declare function clearAllCaches(): void; /** * Reset the four module-level caches to fresh `MemoryCache` instances * with the default TTLs and sizes. Tests use this when they need to * assert against the default behavior after a `configureCaches` call. */ export declare function resetCachesForTesting(): void; /** * Cache an async instance method. * * The cache key combines the supplied prefix, the instance's * `apiBaseUrl` (so testnet and mainnet clients do not collide), and a * JSON serialization of the call's arguments. The instance itself is * NOT serialized — a strong reference to `this` would prevent garbage * collection of short-lived clients and would diverge cache keys for * the same logical call across instances. * * Stampede protection: concurrent callers for the same uncached key * coalesce on a shared `Promise`. The wrapped function runs exactly * once per key per fetch window; subsequent waiters receive the same * result (or the same error). * * Cache bypass: when `instance._cacheEnabled === false`, the wrapped * function is invoked directly with no cache interaction. */ export declare function withInstanceCache Promise>(instance: any, cache: MemoryCache, keyPrefix: string, fn: T): T; //# sourceMappingURL=cache.d.ts.map