UNPKG

bb-inspired

Version:

Core library for BB-inspired NestJS backend

37 lines (36 loc) 1.51 kB
import { RedisCacheService } from './redis-cache.service'; import { MemoryCacheService } from './memory-cache.service'; import { CacheOptions } from './cache.module'; export interface CacheItemOptions { ttl?: number; tags?: string[]; } export interface CacheEntry<T> { value: T; expiresAt?: number; tags?: string[]; } export interface ICacheService { get<T>(key: string): Promise<T | null>; set<T>(key: string, value: T, options?: CacheItemOptions): Promise<void>; delete(key: string): Promise<boolean>; clear(): Promise<void>; has(key: string): Promise<boolean>; invalidateByTag(tag: string): Promise<void>; } export declare class CacheService implements ICacheService { private readonly options; private readonly redisCache; private readonly memoryCache; private readonly logger; private readonly provider; constructor(options: CacheOptions, redisCache: RedisCacheService, memoryCache: MemoryCacheService); get<T>(key: string): Promise<T | null>; set<T>(key: string, value: T, options?: CacheItemOptions): Promise<void>; delete(key: string): Promise<boolean>; clear(): Promise<void>; has(key: string): Promise<boolean>; invalidateByTag(tag: string): Promise<void>; getOrSet<T>(key: string, factory: () => Promise<T> | T, options?: CacheItemOptions): Promise<T>; wrap<T, Args extends any[]>(keyPrefix: string, fn: (...args: Args) => Promise<T> | T, options?: CacheItemOptions): (...args: Args) => Promise<T>; }