UNPKG

nestjs-request-deduplication

Version:

[![npm version](https://badge.fury.io/js/nestjs-request-deduplication.svg)](https://www.npmjs.com/package/nestjs-request-deduplication) [![CI](https://github.com/daniyel/nestjs-request-deduplication/actions/workflows/pr-checks.yml/badge.svg)](https://gith

41 lines (40 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryAdapter = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const keyv_1 = tslib_1.__importDefault(require("keyv")); class MemoryAdapter { constructor(options) { this.options = options; this.logger = new common_1.Logger(MemoryAdapter.name); } init() { return tslib_1.__awaiter(this, void 0, void 0, function* () { this.keyv = new keyv_1.default({ namespace: 'request-deduplication', }); this.logger.log('Memory storage adapter initialized successfully'); }); } get(key) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const value = yield this.keyv.get(key); if (value === undefined) { throw new Error(`Key ${key} not found`); } return value; }); } set(key, value, ttl) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.keyv.set(key, value, ttl); }); } delete(key) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.keyv.delete(key); }); } } exports.MemoryAdapter = MemoryAdapter;