//#region extensions/crypto/src/services/market-cache.d.ts /** * MarketIntel Cache Layer — TTL-based caching for market data API calls. * * Wraps DexScreener, CoinGecko, and other price/market data APIs with * a configurable TTL cache. Benefits: * * 1. Reduces API calls — avoids redundant fetches within the TTL window * 2. Avoids rate limits — DexScreener (300/min), CoinGecko (30/min free) * 3. Faster responses — cached data returns instantly * 4. Resilience — stale data served when API is down (with warning) * * Cache is in-memory (resets on restart). Entries are keyed by * normalized request parameters. */ interface CacheConfig { /** Default TTL for cached entries in ms. Default: 30_000 (30s). */ defaultTtlMs?: number; /** TTL overrides per data category. */ ttlOverrides?: Partial>; /** Max number of cache entries. Default: 500. */ maxEntries?: number; /** Whether to serve stale data when the upstream fetch fails. Default: true. */ serveStaleOnError?: boolean; } type CacheCategory = 'trending' | 'new_pairs' | 'token_price' | 'token_search' | 'token_profile' | 'whale_data' | 'leaderboard' | 'gas_price'; interface CacheEntry { key: string; category: CacheCategory; data: T; cachedAt: number; expiresAt: number; hitCount: number; stale: boolean; } interface CacheStats { entries: number; hits: number; misses: number; staleServes: number; evictions: number; hitRate: number; byCategory: Record; } declare class MarketCache { private cache; private config; private stats; constructor(config?: CacheConfig); /** * Get a cached value, or fetch it using the provided function. * This is the primary interface — wraps any async fetch with caching. */ getOrFetch(category: CacheCategory, key: string, fetcher: () => Promise): Promise; /** * Manually set a cache entry. */ set(category: CacheCategory, key: string, data: T): void; /** * Get a cached value (without fetching). Returns null if not cached or expired. */ get(category: CacheCategory, key: string): T | null; /** * Invalidate a specific cache entry. */ invalidate(category: CacheCategory, key: string): boolean; /** * Invalidate all entries in a category. */ invalidateCategory(category: CacheCategory): number; /** * Clear all cache entries. */ clear(): void; /** * Get cache statistics. */ getStats(): CacheStats; /** * Get all entries for diagnostics (without data payloads). */ getEntryMetadata(): Array<{ key: string; category: CacheCategory; cachedAt: number; expiresAt: number; hitCount: number; stale: boolean; ageMs: number; ttlRemainingMs: number; }>; private buildKey; private getTtl; private evictOldest; } declare function getMarketCache(config?: CacheConfig): MarketCache; declare function resetMarketCache(): void; //#endregion export { CacheCategory, CacheConfig, CacheEntry, CacheStats, getMarketCache, resetMarketCache }; //# sourceMappingURL=market-cache.d.mts.map