UNPKG

@imqueue/pg-cache

Version:

PostgreSQL managed cache on Redis for @imqueue-based service methods

54 lines (53 loc) 2.23 kB
import { Model } from 'sequelize-typescript'; import { MethodDecorator } from './env'; /** * Options expected by @cacheBy() decorator factory */ export interface CacheByOptions { /** * Time to live for cached values. If not specified - default is used. * Default is equivalent of 24 hours. Must be specified in milliseconds. * * @type {number | undefined} */ ttl?: number; /** * Zero-index based position of fields argument in a method arguments, * which are passed at runtime. Fields argument are usually passed from * a client to specify a query map to be extracted and returned from * a service method. For example, fields map can be built from an * incoming GraphQL request using fieldsMap() function from * graphql-fields-list package. * * Usually pg-based @imqueue services, which utilize @imqueue/sequelize * package passing fields as a second argument to service methods, * so if this option is omitted, it will try to check for the second * passed argument. If you need to explicitly disable it, pass -1. * * @see https://github.com/Mikhus/graphql-fields-list * * @type {number} */ fieldsArg?: number; } /** * Retrieves table names as channels from the given model and filter them by * a given fields map, if passed. Returns result as list of table names. * * @access private * @param {typeof Model} model * @param {any} [fields] * @param {string[]} [tables] * @return {string[]} */ export declare function channelsOf(model: typeof Model, fields?: any, tables?: string[]): string[]; /** * Decorator factory @cacheBy(Model, CacheByOptions) * This decorator should be used on a service methods, to set the caching * rules for a method. Caching rules within this decorator are defined by a * passed model, which is treated as a root model of the call and it analyzes * cache invalidation based on passed runtime fields arguments, which * prevents unnecessary cache invalidations. So it is more intellectual way * to invalidate cache instead of any changes on described list of tables. */ export declare function cacheBy(model: typeof Model, options?: CacheByOptions): MethodDecorator;