nestjs-request-deduplication
Version:
[](https://www.npmjs.com/package/nestjs-request-deduplication) [](https://gith
37 lines (36 loc) • 1.11 kB
JavaScript
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);
});
}
}