@nxtedition/lib 23.5.0 → 23.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +4 -0
- package/cache.js +12 -8
- package/package.json +1 -1
package/app.js
CHANGED
package/cache.js
CHANGED
|
@@ -2,7 +2,6 @@ import { LRUCache } from 'lru-cache'
|
|
|
2
2
|
|
|
3
3
|
export class AsyncCache {
|
|
4
4
|
#lru
|
|
5
|
-
#prefix
|
|
6
5
|
#valueSelector
|
|
7
6
|
#keySelector
|
|
8
7
|
#dedupe = new Map()
|
|
@@ -13,7 +12,7 @@ export class AsyncCache {
|
|
|
13
12
|
this.#lru = new LRUCache({ max: 1024 })
|
|
14
13
|
|
|
15
14
|
if (typeof location === 'string') {
|
|
16
|
-
|
|
15
|
+
// Do nothing...
|
|
17
16
|
} else {
|
|
18
17
|
throw new TypeError('location must be undefined or a string')
|
|
19
18
|
}
|
|
@@ -41,7 +40,7 @@ export class AsyncCache {
|
|
|
41
40
|
|
|
42
41
|
if (typeof opts?.stale === 'number' || opts?.stale === undefined) {
|
|
43
42
|
const stale = opts?.stale ?? Number.MAX_SAFE_INTEGER
|
|
44
|
-
this.#stale = () => stale
|
|
43
|
+
this.#stale = (val, key) => stale
|
|
45
44
|
} else if (typeof opts?.stale === 'function') {
|
|
46
45
|
this.#stale = opts.stale
|
|
47
46
|
} else {
|
|
@@ -58,10 +57,10 @@ export class AsyncCache {
|
|
|
58
57
|
|
|
59
58
|
let cached = this.#lru.get(key)
|
|
60
59
|
|
|
61
|
-
if (!cached) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
60
|
+
// if (!cached) {
|
|
61
|
+
// const raw = globalThis.localStorage.getItem(this.#prefix + key)
|
|
62
|
+
// cached = raw ? JSON.parse(raw) : null
|
|
63
|
+
// }
|
|
65
64
|
|
|
66
65
|
if (cached) {
|
|
67
66
|
if (Date.now() < cached.expire) {
|
|
@@ -108,7 +107,12 @@ export class AsyncCache {
|
|
|
108
107
|
value,
|
|
109
108
|
}
|
|
110
109
|
|
|
111
|
-
globalThis.localStorage.setItem(this.#prefix + key, JSON.stringify(cached))
|
|
110
|
+
// globalThis.localStorage.setItem(this.#prefix + key, JSON.stringify(cached))
|
|
111
|
+
|
|
112
112
|
this.#lru.set(key, cached)
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
clear() {
|
|
116
|
+
// TODO (fix): Implement...
|
|
117
|
+
}
|
|
114
118
|
}
|