1 | "use strict"
|
2 | exports.__esModule = true
|
3 |
|
4 | class ModuleCache {
|
5 | constructor(map) {
|
6 | this.map = map || new Map()
|
7 | }
|
8 |
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 | set(cacheKey, result) {
|
15 | this.map.set(cacheKey, { result, lastSeen: Date.now() })
|
16 | return result
|
17 | }
|
18 |
|
19 | get(cacheKey, settings) {
|
20 | if (this.map.has(cacheKey)) {
|
21 | const f = this.map.get(cacheKey)
|
22 |
|
23 | if (Date.now() - f.lastSeen < (settings.lifetime * 1000)) return f.result
|
24 | }
|
25 |
|
26 | return undefined
|
27 | }
|
28 |
|
29 | }
|
30 |
|
31 | ModuleCache.getSettings = function (settings) {
|
32 | const cacheSettings = Object.assign({
|
33 | lifetime: 30,
|
34 | }, settings['import/cache'])
|
35 |
|
36 |
|
37 | if (cacheSettings.lifetime === '∞' || cacheSettings.lifetime === 'Infinity') {
|
38 | cacheSettings.lifetime = Infinity
|
39 | }
|
40 |
|
41 | return cacheSettings
|
42 | }
|
43 |
|
44 | exports.default = ModuleCache
|