Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-manager

Package Overview
Dependencies
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-manager - npm Package Compare versions

Comparing version 5.2.0 to 5.2.1

119

dist/caching.js

@@ -11,32 +11,5 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.caching = void 0;
var stores_1 = require("./stores");
const stores_1 = require("./stores");
/**

@@ -46,59 +19,35 @@ * Generic caching interface that wraps any caching library with a compatible interface.

function caching(factory, args) {
return __awaiter(this, void 0, void 0, function () {
var store;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(factory === 'memory')) return [3 /*break*/, 1];
store = (0, stores_1.memoryStore)(args);
return [3 /*break*/, 4];
case 1:
if (!(typeof factory === 'function')) return [3 /*break*/, 3];
return [4 /*yield*/, factory(args)];
case 2:
store = _a.sent();
return [3 /*break*/, 4];
case 3:
store = factory;
_a.label = 4;
case 4: return [2 /*return*/, {
/**
* Wraps a function in cache. I.e., the first time the function is run,
* its results are stored in cache so subsequent calls retrieve from cache
* instead of calling the function.
* @example
* const result = await cache.wrap('key', () => Promise.resolve(1));
*
*/
wrap: function (key, fn, ttl) { return __awaiter(_this, void 0, void 0, function () {
var value, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, store.get(key)];
case 1:
value = _a.sent();
if (!(value === undefined)) return [3 /*break*/, 4];
return [4 /*yield*/, fn()];
case 2:
result = _a.sent();
return [4 /*yield*/, store.set(key, result, ttl)];
case 3:
_a.sent();
return [2 /*return*/, result];
case 4: return [2 /*return*/, value];
}
});
}); },
store: store,
del: function (key) { return store.del(key); },
get: function (key) { return store.get(key); },
set: function (key, value, ttl) {
return store.set(key, value, ttl);
},
reset: function () { return store.reset(); },
}];
}
});
return __awaiter(this, void 0, void 0, function* () {
let store;
if (factory === 'memory')
store = (0, stores_1.memoryStore)(args);
else if (typeof factory === 'function')
store = yield factory(args);
else
store = factory;
return {
/**
* Wraps a function in cache. I.e., the first time the function is run,
* its results are stored in cache so subsequent calls retrieve from cache
* instead of calling the function.
* @example
* const result = await cache.wrap('key', () => Promise.resolve(1));
*
*/
wrap: (key, fn, ttl) => __awaiter(this, void 0, void 0, function* () {
const value = yield store.get(key);
if (value === undefined) {
const result = yield fn();
yield store.set(key, result, ttl);
return result;
}
return value;
}),
store: store,
del: (key) => store.del(key),
get: (key) => store.get(key),
set: (key, value, ttl) => store.set(key, value, ttl),
reset: () => store.reset(),
};
});

@@ -105,0 +54,0 @@ }

@@ -11,65 +11,2 @@ "use strict";

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -81,205 +18,69 @@ exports.multiCaching = void 0;

function multiCaching(caches) {
var _this = this;
var get = function (key) { return __awaiter(_this, void 0, void 0, function () {
var caches_1, caches_1_1, cache, val, e_1, e_2_1;
var e_2, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 7, 8, 9]);
caches_1 = __values(caches), caches_1_1 = caches_1.next();
_b.label = 1;
case 1:
if (!!caches_1_1.done) return [3 /*break*/, 6];
cache = caches_1_1.value;
_b.label = 2;
case 2:
_b.trys.push([2, 4, , 5]);
return [4 /*yield*/, cache.get(key)];
case 3:
val = _b.sent();
if (val !== undefined)
return [2 /*return*/, val];
return [3 /*break*/, 5];
case 4:
e_1 = _b.sent();
return [3 /*break*/, 5];
case 5:
caches_1_1 = caches_1.next();
return [3 /*break*/, 1];
case 6: return [3 /*break*/, 9];
case 7:
e_2_1 = _b.sent();
e_2 = { error: e_2_1 };
return [3 /*break*/, 9];
case 8:
try {
if (caches_1_1 && !caches_1_1.done && (_a = caches_1.return)) _a.call(caches_1);
}
finally { if (e_2) throw e_2.error; }
return [7 /*endfinally*/];
case 9: return [2 /*return*/];
const get = (key) => __awaiter(this, void 0, void 0, function* () {
for (const cache of caches) {
try {
const val = yield cache.get(key);
if (val !== undefined)
return val;
}
});
}); };
var set = function (key, data, ttl) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(caches.map(function (cache) { return cache.set(key, data, ttl); }))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); };
catch (e) { }
}
});
const set = (key, data, ttl) => __awaiter(this, void 0, void 0, function* () {
yield Promise.all(caches.map((cache) => cache.set(key, data, ttl)));
});
return {
get: get,
set: set,
del: function (key) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(caches.map(function (cache) { return cache.del(key); }))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); },
wrap: function (key, fn, ttl) {
return __awaiter(this, void 0, void 0, function () {
var value, i, e_3, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
i = 0;
_a.label = 1;
case 1:
if (!(i < caches.length)) return [3 /*break*/, 6];
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 5]);
return [4 /*yield*/, caches[i].get(key)];
case 3:
value = _a.sent();
if (value !== undefined)
return [3 /*break*/, 6];
return [3 /*break*/, 5];
case 4:
e_3 = _a.sent();
return [3 /*break*/, 5];
case 5:
i++;
return [3 /*break*/, 1];
case 6:
if (!(value === undefined)) return [3 /*break*/, 9];
return [4 /*yield*/, fn()];
case 7:
result = _a.sent();
return [4 /*yield*/, set(key, result, ttl)];
case 8:
_a.sent();
return [2 /*return*/, result];
case 9: return [4 /*yield*/, Promise.all(caches.slice(0, i).map(function (cache) { return cache.set(key, value, ttl); }))];
case 10:
_a.sent();
_a.label = 11;
case 11: return [2 /*return*/, value];
get,
set,
del: (key) => __awaiter(this, void 0, void 0, function* () {
yield Promise.all(caches.map((cache) => cache.del(key)));
}),
wrap(key, fn, ttl) {
return __awaiter(this, void 0, void 0, function* () {
let value;
let i = 0;
for (; i < caches.length; i++) {
try {
value = yield caches[i].get(key);
if (value !== undefined)
break;
}
});
});
},
reset: function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(caches.map(function (x) { return x.reset(); }))];
case 1:
_a.sent();
return [2 /*return*/];
catch (e) { }
}
if (value === undefined) {
const result = yield fn();
yield set(key, result, ttl);
return result;
}
else {
yield Promise.all(caches.slice(0, i).map((cache) => cache.set(key, value, ttl)));
}
return value;
});
}); },
mget: function () {
var keys = [];
for (var _i = 0; _i < arguments.length; _i++) {
keys[_i] = arguments[_i];
}
return __awaiter(_this, void 0, void 0, function () {
var values, caches_2, caches_2_1, cache, val, e_4, e_5_1;
var e_5, _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
values = new Array(keys.length).fill(undefined);
_c.label = 1;
case 1:
_c.trys.push([1, 8, 9, 10]);
caches_2 = __values(caches), caches_2_1 = caches_2.next();
_c.label = 2;
case 2:
if (!!caches_2_1.done) return [3 /*break*/, 7];
cache = caches_2_1.value;
if (values.every(function (x) { return x !== undefined; }))
return [3 /*break*/, 7];
_c.label = 3;
case 3:
_c.trys.push([3, 5, , 6]);
return [4 /*yield*/, (_b = cache.store).mget.apply(_b, __spreadArray([], __read(keys), false))];
case 4:
val = _c.sent();
val.forEach(function (v, i) {
if (values[i] === undefined && v !== undefined)
values[i] = v;
});
return [3 /*break*/, 6];
case 5:
e_4 = _c.sent();
return [3 /*break*/, 6];
case 6:
caches_2_1 = caches_2.next();
return [3 /*break*/, 2];
case 7: return [3 /*break*/, 10];
case 8:
e_5_1 = _c.sent();
e_5 = { error: e_5_1 };
return [3 /*break*/, 10];
case 9:
try {
if (caches_2_1 && !caches_2_1.done && (_a = caches_2.return)) _a.call(caches_2);
}
finally { if (e_5) throw e_5.error; }
return [7 /*endfinally*/];
case 10: return [2 /*return*/, values];
}
});
});
},
mset: function (args, ttl) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(caches.map(function (cache) { return cache.store.mset(args, ttl); }))];
case 1:
_a.sent();
return [2 /*return*/];
reset: () => __awaiter(this, void 0, void 0, function* () {
yield Promise.all(caches.map((x) => x.reset()));
}),
mget: (...keys) => __awaiter(this, void 0, void 0, function* () {
const values = new Array(keys.length).fill(undefined);
for (const cache of caches) {
if (values.every((x) => x !== undefined))
break;
try {
const val = yield cache.store.mget(...keys);
val.forEach((v, i) => {
if (values[i] === undefined && v !== undefined)
values[i] = v;
});
}
});
}); },
mdel: function () {
var keys = [];
for (var _i = 0; _i < arguments.length; _i++) {
keys[_i] = arguments[_i];
catch (e) { }
}
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(caches.map(function (cache) {
var _a;
return (_a = cache.store).mdel.apply(_a, __spreadArray([], __read(keys), false));
}))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
},
return values;
}),
mset: (args, ttl) => __awaiter(this, void 0, void 0, function* () {
yield Promise.all(caches.map((cache) => cache.store.mset(args, ttl)));
}),
mdel: (...keys) => __awaiter(this, void 0, void 0, function* () {
yield Promise.all(caches.map((cache) => cache.store.mdel(...keys)));
}),
};

@@ -286,0 +87,0 @@ }

@@ -1,4 +0,6 @@

import LRUCache, { Options } from 'lru-cache';
import { LRUCache } from 'lru-cache';
import { Config, Cache, Store } from '../caching';
type Lru = LRUCache<string, unknown>;
type LRU = LRUCache<string, any, unknown>;
type Pre = LRUCache.OptionsTTLLimit<string, any, unknown>;
type Options = Omit<Pre, 'ttlAutopurge'> & Partial<Pick<Pre, 'ttlAutopurge'>>;
export type MemoryConfig = {

@@ -8,7 +10,7 @@ max?: number;

shouldCloneBeforeSet?: boolean;
} & Options<string, unknown> & Config;
} & Options & Config;
export type MemoryStore = Store & {
keyCount: () => number;
dump: Lru['dump'];
load: Lru['load'];
get size(): number;
dump: LRU['dump'];
load: LRU['load'];
};

@@ -15,0 +17,0 @@ export type MemoryCache = Cache<MemoryStore>;

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -22,65 +11,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -91,4 +17,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.memoryStore = void 0;
var lru_cache_1 = __importDefault(require("lru-cache"));
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
const lru_cache_1 = require("lru-cache");
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
function clone(object) {

@@ -104,109 +30,49 @@ if (typeof object === 'object' && object !== null) {

function memoryStore(args) {
var _this = this;
var _a;
var shouldCloneBeforeSet = (args === null || args === void 0 ? void 0 : args.shouldCloneBeforeSet) !== false; // clone by default
var isCacheable = (_a = args === null || args === void 0 ? void 0 : args.isCacheable) !== null && _a !== void 0 ? _a : (function (val) { return val !== undefined; });
var lruOpts = __assign(__assign({}, args), { max: (args === null || args === void 0 ? void 0 : args.max) || 500, ttl: (args === null || args === void 0 ? void 0 : args.ttl) !== undefined ? args.ttl : 0 });
var lruCache = new lru_cache_1.default(lruOpts);
const shouldCloneBeforeSet = (args === null || args === void 0 ? void 0 : args.shouldCloneBeforeSet) !== false; // clone by default
const isCacheable = (_a = args === null || args === void 0 ? void 0 : args.isCacheable) !== null && _a !== void 0 ? _a : ((val) => val !== undefined);
const lruOpts = Object.assign(Object.assign({ ttlAutopurge: true }, args), { max: (args === null || args === void 0 ? void 0 : args.max) || 500, ttl: (args === null || args === void 0 ? void 0 : args.ttl) !== undefined ? args.ttl : 0 });
const lruCache = new lru_cache_1.LRUCache(lruOpts);
return {
del: function (key) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
lruCache.delete(key);
return [2 /*return*/];
});
del(key) {
return __awaiter(this, void 0, void 0, function* () {
lruCache.delete(key);
});
},
get: function (key) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, lruCache.get(key)];
}); }); },
keys: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, __spreadArray([], __read(lruCache.keys()), false)];
}); }); },
mget: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, args.map(function (x) { return lruCache.get(x); })];
}); });
},
mset: function (args, ttl) {
return __awaiter(this, void 0, void 0, function () {
var opt, args_1, args_1_1, _a, key, value;
var e_1, _b;
return __generator(this, function (_c) {
opt = { ttl: ttl !== undefined ? ttl : lruOpts.ttl };
try {
for (args_1 = __values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
_a = __read(args_1_1.value, 2), key = _a[0], value = _a[1];
if (!isCacheable(value))
throw new Error("no cacheable value ".concat(JSON.stringify(value)));
if (shouldCloneBeforeSet)
lruCache.set(key, clone(value), opt);
else
lruCache.set(key, value, opt);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (args_1_1 && !args_1_1.done && (_b = args_1.return)) _b.call(args_1);
}
finally { if (e_1) throw e_1.error; }
}
return [2 /*return*/];
});
get: (key) => __awaiter(this, void 0, void 0, function* () { return lruCache.get(key); }),
keys: () => __awaiter(this, void 0, void 0, function* () { return [...lruCache.keys()]; }),
mget: (...args) => __awaiter(this, void 0, void 0, function* () { return args.map((x) => lruCache.get(x)); }),
mset(args, ttl) {
return __awaiter(this, void 0, void 0, function* () {
const opt = { ttl: ttl !== undefined ? ttl : lruOpts.ttl };
for (const [key, value] of args) {
if (!isCacheable(value))
throw new Error(`no cacheable value ${JSON.stringify(value)}`);
if (shouldCloneBeforeSet)
lruCache.set(key, clone(value), opt);
else
lruCache.set(key, value, opt);
}
});
},
mdel: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return __awaiter(this, void 0, void 0, function () {
var args_2, args_2_1, key;
var e_2, _a;
return __generator(this, function (_b) {
try {
for (args_2 = __values(args), args_2_1 = args_2.next(); !args_2_1.done; args_2_1 = args_2.next()) {
key = args_2_1.value;
lruCache.delete(key);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (args_2_1 && !args_2_1.done && (_a = args_2.return)) _a.call(args_2);
}
finally { if (e_2) throw e_2.error; }
}
return [2 /*return*/];
});
mdel(...args) {
return __awaiter(this, void 0, void 0, function* () {
for (const key of args)
lruCache.delete(key);
});
},
reset: function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
lruCache.clear();
return [2 /*return*/];
});
reset() {
return __awaiter(this, void 0, void 0, function* () {
lruCache.clear();
});
},
ttl: function (key) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, lruCache.getRemainingTTL(key)];
}); }); },
set: function (key, value, opt) {
return __awaiter(this, void 0, void 0, function () {
var ttl;
return __generator(this, function (_a) {
if (!isCacheable(value))
throw new Error("no cacheable value ".concat(JSON.stringify(value)));
if (shouldCloneBeforeSet)
value = clone(value);
ttl = opt !== undefined ? opt : lruOpts.ttl;
lruCache.set(key, value, { ttl: ttl });
return [2 /*return*/];
});
ttl: (key) => __awaiter(this, void 0, void 0, function* () { return lruCache.getRemainingTTL(key); }),
set(key, value, opt) {
return __awaiter(this, void 0, void 0, function* () {
if (!isCacheable(value))
throw new Error(`no cacheable value ${JSON.stringify(value)}`);
if (shouldCloneBeforeSet)
value = clone(value);
const ttl = opt !== undefined ? opt : lruOpts.ttl;
lruCache.set(key, value, { ttl });
});

@@ -217,17 +83,13 @@ },

*/
keyCount: function () { return lruCache.size; },
get size() {
return lruCache.size;
},
/**
* This method is not available in the caching modules.
*/
dump: function () { return lruCache.dump(); },
dump: () => lruCache.dump(),
/**
* This method is not available in the caching modules.
*/
load: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return lruCache.load.apply(lruCache, __spreadArray([], __read(args), false));
},
load: (...args) => lruCache.load(...args),
};

@@ -234,0 +96,0 @@ }

{
"name": "cache-manager",
"version": "5.2.0",
"version": "5.2.1",
"description": "Cache module for Node.js",

@@ -33,24 +33,24 @@ "main": "dist/index.js",

"lodash.clonedeep": "^4.5.0",
"lru-cache": "~7.18.3"
"lru-cache": "~9.1.1"
},
"devDependencies": {
"@commitlint/cli": "17.4.4",
"@commitlint/config-conventional": "17.4.4",
"@commitlint/cli": "17.6.1",
"@commitlint/config-conventional": "17.6.1",
"@faker-js/faker": "7.6.0",
"@release-it/conventional-changelog": "5.1.1",
"@types/lodash.clonedeep": "4.5.7",
"@types/node": "18.15.5",
"@typescript-eslint/eslint-plugin": "5.56.0",
"@typescript-eslint/parser": "5.56.0",
"@vitest/coverage-c8": "0.29.7",
"dotenv-cli": "7.1.0",
"eslint": "8.36.0",
"@types/node": "18.16.0",
"@typescript-eslint/eslint-plugin": "5.59.0",
"@typescript-eslint/parser": "5.59.0",
"@vitest/coverage-c8": "0.30.1",
"dotenv-cli": "7.2.1",
"eslint": "8.39.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-prettier": "4.2.1",
"husky": "8.0.3",
"lint-staged": "13.2.0",
"prettier": "2.8.5",
"release-it": "15.9.0",
"typescript": "5.0.2",
"vitest": "0.29.7"
"lint-staged": "13.2.1",
"prettier": "2.8.8",
"release-it": "15.10.1",
"typescript": "5.0.4",
"vitest": "0.30.1"
},

@@ -57,0 +57,0 @@ "lint-staged": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc