import { type Milliseconds } from '@goatlab/js-utils'; import type { ClusterOptions } from 'ioredis'; import type { Options } from 'keyv'; declare const Keyv: any; export interface CacheClusterConfig { nodes: Array<{ host: string; port: number; }>; options?: ClusterOptions; } export interface CacheOptions extends Options { usesLRUMemory?: boolean; tenantId?: string; /** * When true (default), Redis connection is deferred until first use. * This prevents connection exhaustion during Cloud Run/serverless deployments * where old and new containers may briefly run simultaneously. * * Set to false for eager connection (fail-fast behavior). * * @default true */ lazy?: boolean; /** * Redis Cluster configuration. * When provided, the cache connects to a Redis Cluster instead of standalone Redis. * Takes precedence over the `connection` string for store creation. */ cluster?: CacheClusterConfig; } export declare class Cache extends Keyv { private ns; private _tenantId?; private usesLRUMemory?; private keyvLru; private memoryCache; private connectionString?; private connectionPool; private lazyStore?; constructor({ connection, opts, }: { connection: string | undefined; opts?: CacheOptions; }); get tenantId(): string | undefined; /** * Check if the cache is using lazy initialization */ isLazy(): boolean; /** * Check if the Redis connection is established (for lazy mode) */ isConnected(): boolean; private isValidResult; private isNotNullish; private isNotEmptyString; private isNotEmptyArray; private isNotEmptyObject; get(key: string | string[]): Promise; delete(key: string): Promise; has(key: string[]): Promise; has(key: string): Promise; /** * Get an item from the cache, or execute the given Closure and store the result. * * @param string $key * @param int $ms - time in milliseconds * @param $callback */ remember(key: string, ms: Milliseconds, fx: () => Promise): Promise; /** * Get an item from the cache, or execute the given Closure and store the result forever. * * @param string $key * @param \Closure $callback */ rememberForever(key: string, fx: () => Promise): Promise; /** * Retrieve an item from the cache and delete it. * * @param string $key */ pull(key: string): Promise; /** * Remove an item from the cache. * * @param string $key * @return bool */ forget(key: string): Promise; /** * Remove all items from the cache in the current namespace. * * Note: We use iterator-based deletion instead of KeyvRedis's clear() because * clear() relies on Redis Sets to track keys. Keys created before proper namespace * setup or with useRedisSets:false won't be in those sets and won't be deleted. * The iterator uses Redis SCAN which finds ALL keys matching the namespace pattern. * * @return void */ flush(): Promise; /** * SCAN a single Redis node for keys matching a pattern and UNLINK them. * Used for cluster-safe flush operations where `keys()` is not viable. */ private scanAndUnlink; /** * Get the underlying Redis client if available. * Ensures lazy connection is established first. * Returns undefined for non-Redis stores. */ private getRedisClient; deleteWhereStartsWith(value: string): Promise; getValueWhereKeyStartsWith(value: string): Promise; /** * Dispose of this cache instance and release the Redis connection. * After calling this, the cache instance should not be used. * The connection will remain in the pool for reuse by other instances. */ dispose(): void; /** * Disconnect the Redis connection for this cache instance. * This removes the connection from the pool entirely. * Use this when you're certain no other instances need this connection. */ disconnect(): Promise; } export {};