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

37 lines (36 loc) 1.11 kB
import { __awaiter } from "tslib"; import { Logger } from '@nestjs/common'; import Keyv from 'keyv'; export class MemoryAdapter { constructor(options) { this.options = options; this.logger = new Logger(MemoryAdapter.name); } init() { return __awaiter(this, void 0, void 0, function* () { this.keyv = new Keyv({ namespace: 'request-deduplication', }); this.logger.log('Memory storage adapter initialized successfully'); }); } get(key) { return __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 __awaiter(this, void 0, void 0, function* () { yield this.keyv.set(key, value, ttl); }); } delete(key) { return __awaiter(this, void 0, void 0, function* () { yield this.keyv.delete(key); }); } }