We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ea2987c commit 5b524b7Copy full SHA for 5b524b7
src/getLru.ts
@@ -0,0 +1,23 @@
1
+import type { LRU } from './types'
2
+export function getLru(max = 50): LRU {
3
+ return {
4
+ set(key: string, value: any) {
5
+ if (this.cache.has(key))
6
+ this.cache.delete(key)
7
+ this.cache.set(key, value)
8
+ if (this.cache.size > this.max)
9
+ this.cache.delete(this.cache.keys().next().value)
10
+ },
11
+ get(key: string) {
12
+ if (this.cache.has(key)) {
13
+ const value = this.cache.get(key)
14
15
16
+ return value
17
+ }
18
+ return undefined
19
20
+ cache: new Map(),
21
+ max,
22
23
+}
0 commit comments