querysub 0.465.0 → 0.466.0
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/package.json +1 -1
- package/src/storage/diskCache2.ts +13 -9
package/package.json
CHANGED
|
@@ -14,7 +14,12 @@ let requestPersist = lazy(() => {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
type DiskCache = {
|
|
18
|
+
get(key: string): Promise<Buffer | undefined>;
|
|
19
|
+
set(key: string, value: Buffer): void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
let existingDiskCaches = new Map<string, DiskCache>();
|
|
18
23
|
/** NOTE: Slower than diskCache for reading, but... less flakey, and faster at writing. ALSO,
|
|
19
24
|
* doesn't synchronously block, which diskCache does.
|
|
20
25
|
*/
|
|
@@ -24,10 +29,7 @@ export function bufferDiskCache(
|
|
|
24
29
|
/** Default = 64MB */
|
|
25
30
|
inMemoryLimit?: number;
|
|
26
31
|
}
|
|
27
|
-
): {
|
|
28
|
-
get(key: string): Promise<Buffer | undefined>;
|
|
29
|
-
set(key: string, value: Buffer): void;
|
|
30
|
-
} {
|
|
32
|
+
): DiskCache {
|
|
31
33
|
if (isNode()) {
|
|
32
34
|
return {
|
|
33
35
|
get: async (key: string) => undefined,
|
|
@@ -37,10 +39,10 @@ export function bufferDiskCache(
|
|
|
37
39
|
let { uniqueName } = config;
|
|
38
40
|
const inMemoryLimit = config.inMemoryLimit ?? 64 * 1024 * 1024;
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
let prev = existingDiskCaches.get(uniqueName);
|
|
43
|
+
if (prev) {
|
|
44
|
+
return prev;
|
|
42
45
|
}
|
|
43
|
-
existingDiskCaches.add(uniqueName);
|
|
44
46
|
uniqueName = "diskCache7_" + uniqueName;
|
|
45
47
|
|
|
46
48
|
let totalBufferCacheSize = 0;
|
|
@@ -89,10 +91,12 @@ export function bufferDiskCache(
|
|
|
89
91
|
await writeFile({ path, data });
|
|
90
92
|
};
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
let diskCache: DiskCache = {
|
|
93
95
|
get: getDiskCached,
|
|
94
96
|
set: (key, value) => logErrors(setDiskCached(key, value)),
|
|
95
97
|
};
|
|
98
|
+
existingDiskCaches.set(uniqueName, diskCache);
|
|
99
|
+
return diskCache;
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
|