import type IIdempotencyStore from "./IIdempotencyStore"; /** * In-memory implementation of IIdempotencyStore. * Supports TTL-based expiration with automatic cleanup. * * Note: This implementation is suitable for single-process applications. * For distributed systems, use a Redis or database-backed implementation. */ export default class InMemoryIdempotencyStore implements IIdempotencyStore { private readonly keys; private cleanupInterval; private readonly cleanupIntervalMs; /** * Creates a new InMemoryIdempotencyStore. * @param cleanupIntervalMs Interval for automatic cleanup of expired keys (default: 60000ms = 1 minute) */ constructor(cleanupIntervalMs?: number); exists(key: string): Promise; mark(key: string, ttl?: number): Promise; remove(key: string): Promise; /** * Manually trigger cleanup of expired keys. * @returns The number of keys removed */ cleanup(): number; /** * Get the current number of stored keys. */ size(): number; /** * Clear all stored keys. */ clear(): void; /** * Stop the automatic cleanup interval. * Should be called when the store is no longer needed to prevent memory leaks. */ stopCleanup(): void; private startCleanup; }