pg-smart-search
API Reference

Cache Providers API

API reference for MemoryCacheProvider and RedisCacheProvider used in pg-smart-search.

Cache Providers API

CacheProvider Interface

All cache providers must implement the CacheProvider interface.

export interface CacheProvider {
  get<T>(key: string): Promise<T | null>;
  set<T>(key: string, value: T, ttlSeconds?: number): Promise<void>;
  delete(key: string): Promise<void>;
  clear(): 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, for sharing cache state across multiple Node.js instances. It's a thin get/set/delete/clear wrapper around your Redis client -- no distributed locking. Concurrent identical searches are only deduplicated within a single process via the engine's in-flight request tracking (see Reliability); across separate instances, a simultaneous cache miss on the same key still results in each instance querying the database.

Constructor

new RedisCacheProvider(client: RedisClient)

Parameters:

  • client: An initialized Redis client instance (compatible with ioredis or redis npm packages). The client must be connected before passing it to the provider.