Skip to content

Commit 1d8afd9

Browse files
committed
feature/cache: Add lru-cache wrapper
1 parent 393fc22 commit 1d8afd9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lru-cache.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const lru = require('lru-cache');
2+
3+
module.exports = class LRU {
4+
constructor({ maxItems }) {
5+
this.cache = lru(maxItems);
6+
}
7+
8+
get(key) {
9+
return Promise.resolve(this.cache.get(key));
10+
}
11+
12+
set(key, value, options) {
13+
const { maxAge } = options || {};
14+
this.cache.set(key, value, maxAge);
15+
return Promise.resolve(key);
16+
}
17+
18+
values() {
19+
return Promise.resolve(this.cache.values());
20+
}
21+
22+
length() {
23+
return this.cache.length;
24+
}
25+
};

0 commit comments

Comments
 (0)