1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.lru = void 0;
|
7 | const flru_1 = __importDefault(require("flru"));
|
8 | const cache = (0, flru_1.default)(3);
|
9 |
|
10 |
|
11 |
|
12 | function lru(fn, keyFn = (...args) => `${args[0]}`, maxSize = 16) {
|
13 | const cache = (0, flru_1.default)(maxSize);
|
14 | return (...args) => {
|
15 | const key = keyFn(...args);
|
16 | let v = cache.get(key);
|
17 | if (cache.has(key))
|
18 | return cache.get(key);
|
19 | v = fn(...args);
|
20 | cache.set(key, v);
|
21 | return v;
|
22 | };
|
23 | }
|
24 | exports.lru = lru;
|
25 | //# sourceMappingURL=lru.js.map |
\ | No newline at end of file |