@helia/verified-fetch 2.6.17 → 2.6.18
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/dist/index.min.js +49 -49
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.js +5 -5
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/byte-range-context.d.ts.map +1 -1
- package/dist/src/utils/dir-index-html.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.d.ts +2 -2
- package/dist/src/utils/parse-url-string.js +9 -7
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/responses.d.ts +4 -4
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +3 -3
- package/dist/src/utils/tlru.d.ts.map +1 -1
- package/dist/src/utils/tlru.js +7 -13
- package/dist/src/utils/tlru.js.map +1 -1
- package/dist/src/verified-fetch.js +5 -5
- package/dist/src/verified-fetch.js.map +1 -1
- package/dist/typedoc-urls.json +5 -3
- package/package.json +14 -22
- package/src/index.ts +5 -5
- package/src/types.ts +1 -1
- package/src/utils/dir-index-html.ts +2 -2
- package/src/utils/libp2p-defaults.browser.ts +1 -1
- package/src/utils/libp2p-defaults.ts +1 -1
- package/src/utils/parse-url-string.ts +7 -7
- package/src/utils/responses.ts +4 -4
- package/src/utils/tlru.ts +8 -18
- package/src/verified-fetch.ts +6 -6
package/src/utils/tlru.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import QuickLRU from 'quick-lru'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Time Aware Least Recent Used Cache
|
|
@@ -6,30 +6,20 @@ import hashlru from 'hashlru'
|
|
|
6
6
|
* @see https://arxiv.org/pdf/1801.00390
|
|
7
7
|
*/
|
|
8
8
|
export class TLRU<T> {
|
|
9
|
-
private readonly lru:
|
|
9
|
+
private readonly lru: QuickLRU<string, T>
|
|
10
10
|
|
|
11
11
|
constructor (maxSize: number) {
|
|
12
|
-
this.lru =
|
|
12
|
+
this.lru = new QuickLRU({ maxSize })
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
get (key: string): T | undefined {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (value != null) {
|
|
19
|
-
if (value.expire != null && value.expire < Date.now()) {
|
|
20
|
-
this.lru.remove(key)
|
|
21
|
-
|
|
22
|
-
return undefined
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return value.value
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return undefined
|
|
16
|
+
return this.lru.get(key)
|
|
29
17
|
}
|
|
30
18
|
|
|
31
19
|
set (key: string, value: T, ttlMs: number): void {
|
|
32
|
-
this.lru.set(key,
|
|
20
|
+
this.lru.set(key, value, {
|
|
21
|
+
maxAge: Date.now() + ttlMs
|
|
22
|
+
})
|
|
33
23
|
}
|
|
34
24
|
|
|
35
25
|
has (key: string): boolean {
|
|
@@ -43,7 +33,7 @@ export class TLRU<T> {
|
|
|
43
33
|
}
|
|
44
34
|
|
|
45
35
|
remove (key: string): void {
|
|
46
|
-
this.lru.
|
|
36
|
+
this.lru.delete(key)
|
|
47
37
|
}
|
|
48
38
|
|
|
49
39
|
clear (): void {
|
package/src/verified-fetch.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ipns as heliaIpns } from '@helia/ipns'
|
|
2
2
|
import { prefixLogger } from '@libp2p/logger'
|
|
3
|
-
import { LRUCache } from 'lru-cache'
|
|
4
3
|
import { CustomProgressEvent } from 'progress-events'
|
|
4
|
+
import QuickLRU from 'quick-lru'
|
|
5
5
|
import { ByteRangeContextPlugin } from './plugins/plugin-handle-byte-range-context.js'
|
|
6
6
|
import { CarPlugin } from './plugins/plugin-handle-car.js'
|
|
7
7
|
import { DagCborPlugin } from './plugins/plugin-handle-dag-cbor.js'
|
|
@@ -62,7 +62,7 @@ export class VerifiedFetch {
|
|
|
62
62
|
private readonly ipns: IPNS
|
|
63
63
|
private readonly log: Logger
|
|
64
64
|
private readonly contentTypeParser: ContentTypeParser | undefined
|
|
65
|
-
private readonly blockstoreSessions:
|
|
65
|
+
private readonly blockstoreSessions: QuickLRU<string, SessionBlockstore>
|
|
66
66
|
private serverTimingHeaders: string[] = []
|
|
67
67
|
private readonly withServerTiming: boolean
|
|
68
68
|
private readonly plugins: VerifiedFetchPlugin[] = []
|
|
@@ -72,10 +72,10 @@ export class VerifiedFetch {
|
|
|
72
72
|
this.log = helia.logger.forComponent('helia:verified-fetch')
|
|
73
73
|
this.ipns = ipns ?? heliaIpns(helia)
|
|
74
74
|
this.contentTypeParser = init?.contentTypeParser ?? contentTypeParser
|
|
75
|
-
this.blockstoreSessions = new
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
this.blockstoreSessions = new QuickLRU({
|
|
76
|
+
maxSize: init?.sessionCacheSize ?? SESSION_CACHE_MAX_SIZE,
|
|
77
|
+
maxAge: init?.sessionTTLms ?? SESSION_CACHE_TTL_MS,
|
|
78
|
+
onEviction: (key, store) => {
|
|
79
79
|
store.close()
|
|
80
80
|
}
|
|
81
81
|
})
|