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

54 lines (53 loc) 2.37 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var CacheableModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheableModule = void 0; const common_1 = require("@nestjs/common"); const cache_manager_1 = require("@nestjs/cache-manager"); const cacheable_helpers_1 = require("./cacheable.helpers"); const CACHEABLE_CONFIG = "CACHEABLE_CONFIG"; let CacheableModule = CacheableModule_1 = class CacheableModule { constructor(cacheManager, config) { this.config = config; (0, cacheable_helpers_1.setCacheManager)(cacheManager); } onModuleInit() { (0, cacheable_helpers_1.setCacheConfiguration)(this.config); console.log(this.config); } static forRootAsync(options) { const providers = [ { provide: CACHEABLE_CONFIG, useFactory: options.useFactory, inject: options.inject, }, ]; return { module: CacheableModule_1, imports: options.imports, providers: providers, exports: providers, }; } }; exports.CacheableModule = CacheableModule; exports.CacheableModule = CacheableModule = CacheableModule_1 = __decorate([ (0, common_1.Global)(), (0, common_1.Module)({}), __param(0, (0, common_1.Inject)(cache_manager_1.CACHE_MANAGER)), __param(1, (0, common_1.Inject)(CACHEABLE_CONFIG)), __metadata("design:paramtypes", [Object, Object]) ], CacheableModule);