UNPKG

osrs-tools

Version:

A comprehensive TypeScript library for Old School RuneScape (OSRS) data and utilities, including quest data, skill requirements, and game item information

74 lines 1.96 kB
/** * Interface for cache options */ interface CacheOptions { /** Maximum number of items to store */ maxSize?: number; /** Time-to-live in milliseconds */ ttl?: number; } /** * Generic cache implementation with LRU eviction and TTL support */ export declare class Cache<T> { private store; private readonly maxSize; private readonly ttl?; /** * Creates a new Cache instance * @param options Cache configuration options */ constructor(options?: CacheOptions); /** * Store a value in the cache * @param key Cache key * @param value Value to store * @param ttl Optional TTL override for this item */ set(key: string, value: T, ttl?: number): void; /** * Retrieve a value from the cache * @param key Cache key * @returns Stored value or undefined if not found/expired */ get(key: string): T | undefined; /** * Remove an item from the cache * @param key Cache key * @returns true if item was found and removed */ delete(key: string): boolean; /** * Clear all items from the cache */ clear(): void; /** * Get the number of items in the cache */ get size(): number; /** * Get all valid keys in the cache * @returns Array of cache keys */ keys(): string[]; /** * Remove all expired items from the cache * @returns Number of items removed */ prune(): number; /** * Check if a key exists in the cache and isn't expired * @param key Cache key * @returns true if key exists and isn't expired */ has(key: string): boolean; /** * Get or set a cache value * @param key Cache key * @param factory Function to create value if not found * @returns Cached or newly created value */ getOrSet(key: string, factory: () => Promise<T>): Promise<T>; } export {}; //# sourceMappingURL=cache.d.ts.map