1 | import { MemoCache } from '@naturalcycles/js-lib'
|
2 | import LRUCache = require('lru-cache')
|
3 |
|
4 | export type LRUMemoCacheOpts = LRUCache.Options<string, any>
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export class LRUMemoCache implements MemoCache {
|
14 | constructor(opt: LRUMemoCacheOpts) {
|
15 | this.lru = new LRUCache<string, any>(opt)
|
16 | }
|
17 |
|
18 | private lru!: LRUCache<string, any>
|
19 |
|
20 | has(k: any): boolean {
|
21 | return this.lru.has(k)
|
22 | }
|
23 |
|
24 | get(k: any): any {
|
25 | return this.lru.get(k)
|
26 | }
|
27 |
|
28 | set(k: any, v: any): void {
|
29 | this.lru.set(k, v)
|
30 | }
|
31 |
|
32 | clear(): void {
|
33 | this.lru.reset()
|
34 | }
|
35 | }
|