@imqueue/pg-cache
Version:
PostgreSQL managed cache on Redis for @imqueue-based service methods
41 lines (40 loc) • 1.49 kB
TypeScript
import { type FilteredChannels, type PgCacheChannel } from './PgCache.js';
import { type MethodDecorator } from './env.js';
/**
* Options for the {@link cacheWith} method decorator: which tables invalidate the
* cached result, how long it may live, and the tag it is stored under.
*/
export interface CacheWithOptions {
/**
* Time to live in milliseconds. By default is equivalent to 24 hours
*
*/
ttl?: number;
/**
* PgBubSub channels to listen for invalidation. Usually channels are
* table names.
*
*/
channels: string[] | FilteredChannels;
/**
* Tag to use for this cache when set a value
*
*/
tag?: string;
}
/**
* Makes channel entry from a given channel name, class method name and options.
*
* @param name - notification channel, i.e. the watched table name
* @param method - decorated method to invalidate when that channel fires
* @param options - which channels invalidate the result, its TTL and cache tag decorator options; only the per-channel filter is read here
*/
export declare function makeChannel(name: string, method: string, options: CacheWithOptions): PgCacheChannel;
/**
* Decorator factory `@cacheWith`(CacheWithOptions)
* This decorator should be used on a service methods, to set the caching
* rules for a method.
*
* @param options - which channels invalidate the result, its TTL and cache tag
*/
export declare function cacheWith(options: CacheWithOptions): MethodDecorator;