import { OnModuleInit } from '@nestjs/common'; import { Cache } from 'cache-manager'; import { CacheModuleOptions } from './cache-module-options.interface'; /** * Service responsible for centralized cache management. * * This service abstracts caching operations such as retrieving, * storing, and deleting values. It supports Redis caching using * Azure Workload Identity for authentication and handles automatic * token refresh to maintain cache connectivity. */ export declare class CacheService implements OnModuleInit { private readonly namespace; private readonly options; private readonly cache; private readonly logger; /** * Constructs CacheService with injected dependencies. * * @param namespace Optional namespace to scope cache keys and avoid collisions. * @param options Configuration options for cache connection (e.g., Redis credentials). * @param cache Injected NestJS cache manager instance for cache operations. */ constructor(namespace: string | undefined, options: CacheModuleOptions, cache: Cache); /** * Lifecycle hook called after module initialization. * Ensures cache stores are configured and ready. */ onModuleInit(): void; /** * Sets up the cache store, connecting to Redis with Azure Workload Identity. * Automatically refreshes the Redis access token before expiration. * * If Redis config is incomplete or connection fails, falls back to empty store. */ private initializeCacheStore; /** * Retrieves the cached value by key. * * @param key Cache key. * @returns The cached value or null if not found. */ fetch(key: string): Promise; /** * Stores a value in the cache under the given key with optional TTL. * * @param key Cache key. * @param value Value to store. * @param expiration Optional time to live in seconds. */ store(key: string, value: T, expiration?: number): Promise; /** * Removes a cached value by key. * * @param key Cache key to delete. */ remove(key: string): Promise; /** * Clears all cached entries. */ clearAll(): Promise; /** * Retrieves a value from the cache or fetches it using the provided function * if not found, then stores it with an optional expiration. * * @param key Cache key. * @param fetcher Function that fetches the data if cache miss occurs. * @param expiration Optional TTL in seconds. * @returns Cached or freshly fetched value. */ fetchOrStore(key: string, fetcher: () => Promise, expiration?: number): Promise; }