API Reference
Cache Providers API
API reference for MemoryCacheProvider and RedisCacheProvider used in pg-smart-search.
Cache Providers API
ICacheProvider Interface
All cache providers must implement the ICacheProvider interface.
export interface ICacheProvider {
get<T>(key: string): Promise<T | null>;
set<T>(key: string, value: T, ttl?: number): Promise<void>;
delete(key: string): Promise<void>;
}MemoryCacheProvider
A simple in-memory cache using a JavaScript Map. Suitable for single-instance deployments.
Constructor
new MemoryCacheProvider();No configuration parameters are required.
RedisCacheProvider
A distributed cache backed by Redis. Includes Redlock-style deduplication to prevent cache stampedes.
Constructor
new RedisCacheProvider(client: RedisClient)Parameters:
client: An initialized Redis client instance (compatible withioredisorredisnpm packages). The client must be connected before passing it to the provider.