@hz-9/a5-cache
Version:
Cache module for the @hz-9/a5-* series of repositories, based on cache-manager.
63 lines (62 loc) • 1.2 kB
TypeScript
import type { Cache } from 'cache-manager';
import type { Keyv } from 'keyv';
/**
* A5 缓存模块配置接口
*
* @public
*/
export interface A5CacheConstructorOptions {
/**
* 缓存配置
*
* 可以是单个存储配置或多个存储配置(用于多层缓存)
*/
stores?: Keyv[];
/**
* 缓存 TTL(毫秒)
*/
ttl?: number;
/**
* 刷新阈值(毫秒)
*/
refreshThreshold?: number;
/**
* 是否刷新所有存储
*
* @defaultValue false
*/
refreshAllStores?: boolean;
/**
* 是否非阻塞模式
*
* @defaultValue false
*/
nonBlocking?: boolean;
/**
* 缓存 ID
*/
cacheId?: string;
}
/**
* A5 缓存实例接口
*
* 基于 cache-manager 的 Cache 类型
*
* @public
*/
export type A5CacheInstance = Cache;
/**
* A5 缓存包装选项接口
*
* @public
*/
export interface A5CacheWrapOptions<T = unknown> {
/**
* 过期时间(毫秒)或计算函数
*/
ttl?: number | ((value: T) => number);
/**
* 刷新阈值(毫秒)或计算函数
*/
refreshThreshold?: number | ((value: T) => number);
}