1 | "use strict";
|
2 |
|
3 |
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | exports.LruCache = void 0;
|
6 | const DEFAULT_MAX_SIZE = 128;
|
7 |
|
8 | class LruCache {
|
9 | constructor(options = {}) {
|
10 | this._map = new Map();
|
11 | this._maxSize = (options === null || options === void 0 ? void 0 : options.maxSize) || DEFAULT_MAX_SIZE;
|
12 | }
|
13 | |
14 |
|
15 |
|
16 | get size() {
|
17 | return this._map.size;
|
18 | }
|
19 | |
20 |
|
21 |
|
22 | clear() {
|
23 | this._map.clear();
|
24 | }
|
25 | |
26 |
|
27 |
|
28 | get(key) {
|
29 | const item = this._map.get(key) || null;
|
30 | if (item != null) {
|
31 | this._map.delete(key);
|
32 | this._map.set(key, item);
|
33 | }
|
34 | return item;
|
35 | }
|
36 | |
37 |
|
38 |
|
39 | set(key, value) {
|
40 | if (this._map.size >= this._maxSize) {
|
41 | this._map.delete(this._map.keys().next().value);
|
42 | }
|
43 | this._map.set(key, value);
|
44 | }
|
45 | }
|
46 | exports.LruCache = LruCache;
|
47 |
|
\ | No newline at end of file |