UNPKG

@nhan2804/nestjs-cacheable

Version:

@nestjs/cacheable is a flexible caching library for NestJS that leverages Redis for efficient and scalable storage. With support for function-level caching through easy-to-use decorators, it allows developers to seamlessly enhance performance while mainta

24 lines (23 loc) 638 B
import { Cache } from "cache-manager"; import { CacheableConfiguration } from "./cacheable.interfaces"; export let cache: Cache; export let cacheConfigOption: CacheableConfiguration = { ttl: 1000 * 60, }; export const setCacheManager = (c: Cache) => { cache = c; }; export const getCacheManager = (): Cache => { return cache; }; export const setCacheConfiguration = (c: CacheableConfiguration) => { if (c.refreshThreshold) { cacheConfigOption.refreshThreshold = c.refreshThreshold; } if (c.ttl) { cacheConfigOption.ttl = c.ttl; } if (c.isDev) { cacheConfigOption.isDev = c.isDev; } };