UNPKG

runtime-memory-cache

Version:

A lightweight, high-performance in-memory cache for Node.js with TTL support, configurable eviction policies (FIFO/LRU), statistics tracking, and zero dependencies.

65 lines (64 loc) 1.84 kB
import { CacheEntry, EvictionPolicy, MemoryUsage } from './types'; /** * Utility class for cache-related operations */ export declare class CacheUtils { /** * Check if a cache entry is expired */ static isExpired(entry: CacheEntry): boolean; /** * Calculate expiration timestamp */ static calculateExpiresAt(ttl?: number, defaultTtl?: number): number | undefined; /** * Create a new cache entry */ static createEntry(value: any, expiresAt?: number): CacheEntry; /** * Update access time for LRU tracking */ static updateAccessTime(entry: CacheEntry): void; /** * Get the key to evict based on eviction policy */ static getKeyToEvict<K>(store: Map<K, CacheEntry>, evictionPolicy: EvictionPolicy): K | undefined; /** * Get the first key from a Map (for FIFO eviction) * @deprecated Use getKeyToEvict instead */ static getFirstKey<K>(map: Map<K, any>): K | undefined; /** * Remove expired entries from the cache */ static cleanupExpired<K>(store: Map<K, CacheEntry>): number; /** * Estimate memory usage of a cache entry */ static estimateEntrySize(key: string, entry: CacheEntry): number; /** * Estimate memory size of a value */ static estimateValueSize(value: any): number; /** * Calculate total memory usage of cache */ static calculateMemoryUsage<K>(store: Map<K, CacheEntry>): MemoryUsage; } /** * Validation utilities for cache operations */ export declare class ValidationUtils { /** * Validate cache key */ static validateKey(key: string): void; /** * Validate TTL value */ static validateTTL(ttl: number): void; /** * Validate cache options */ static validateCacheOptions(options: any): void; }