extra-disk-store 0.2.1 → 0.3.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/README.md
CHANGED
|
@@ -38,8 +38,8 @@ class DiskStore {
|
|
|
38
38
|
### DiskStoreWithCache
|
|
39
39
|
```ts
|
|
40
40
|
interface ICache {
|
|
41
|
-
set(key: string, value: Buffer |
|
|
42
|
-
get(key: string): Buffer |
|
|
41
|
+
set(key: string, value: Buffer | false): void
|
|
42
|
+
get(key: string): Buffer | false | undefined
|
|
43
43
|
delete(key: string): void
|
|
44
44
|
clear(): void
|
|
45
45
|
}
|
|
@@ -52,7 +52,7 @@ class DiskStoreWithCache {
|
|
|
52
52
|
|
|
53
53
|
close(): Promise<void>
|
|
54
54
|
|
|
55
|
-
has(key: string):
|
|
55
|
+
has(key: string): boolean
|
|
56
56
|
get(key: string): Buffer | undefined
|
|
57
57
|
set(key: string, value: Buffer): Promise<void>
|
|
58
58
|
delete(key: string): Promise<void>
|
|
@@ -82,7 +82,7 @@ class DiskStoreView<K, V> {
|
|
|
82
82
|
) {}
|
|
83
83
|
|
|
84
84
|
has(key: K): Promise<boolean>
|
|
85
|
-
get(key: K): Promise<V | undefined>
|
|
85
|
+
get(key: K): Promise<V | undefined>
|
|
86
86
|
set(key: K, value: V): Promise<void>
|
|
87
87
|
delete(key: K): Promise<void>
|
|
88
88
|
clear(): Promise<void>
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DiskStore } from './disk-store';
|
|
3
3
|
export interface ICache {
|
|
4
|
-
set(key: string, value: Buffer |
|
|
5
|
-
get(key: string): Buffer |
|
|
4
|
+
set(key: string, value: Buffer | false): void;
|
|
5
|
+
get(key: string): Buffer | false | undefined;
|
|
6
6
|
delete(key: string): void;
|
|
7
7
|
clear(): void;
|
|
8
8
|
}
|
|
9
|
-
export declare enum CacheKeyType {
|
|
10
|
-
Exist = 0,
|
|
11
|
-
Value = 1
|
|
12
|
-
}
|
|
13
9
|
export declare class DiskStoreWithCache {
|
|
14
10
|
private store;
|
|
15
11
|
private cache;
|
|
16
12
|
constructor(store: DiskStore, cache: ICache);
|
|
17
13
|
close(): Promise<void>;
|
|
18
|
-
has(key: string):
|
|
14
|
+
has(key: string): boolean;
|
|
19
15
|
get(key: string): Buffer | undefined;
|
|
20
16
|
set(key: string, value: Buffer): Promise<void>;
|
|
21
17
|
delete(key: string): Promise<void>;
|
|
22
18
|
clear(): Promise<void>;
|
|
23
19
|
keys(): IterableIterator<string>;
|
|
24
20
|
}
|
|
25
|
-
export declare function createCacheKey(type: CacheKeyType, key: string): string;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DiskStoreWithCache = void 0;
|
|
4
4
|
const prelude_1 = require("@blackglory/prelude");
|
|
5
|
-
var CacheKeyType;
|
|
6
|
-
(function (CacheKeyType) {
|
|
7
|
-
CacheKeyType[CacheKeyType["Exist"] = 0] = "Exist";
|
|
8
|
-
CacheKeyType[CacheKeyType["Value"] = 1] = "Value";
|
|
9
|
-
})(CacheKeyType = exports.CacheKeyType || (exports.CacheKeyType = {}));
|
|
10
5
|
class DiskStoreWithCache {
|
|
11
6
|
constructor(store, cache) {
|
|
12
7
|
this.store = store;
|
|
@@ -15,39 +10,53 @@ class DiskStoreWithCache {
|
|
|
15
10
|
async close() {
|
|
16
11
|
await this.store.close();
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
if ((0, prelude_1.isBoolean)(result)) {
|
|
13
|
+
has(key) {
|
|
14
|
+
const result = this.cache.get(key);
|
|
15
|
+
if (result === false) {
|
|
22
16
|
return result;
|
|
23
17
|
}
|
|
18
|
+
else if ((0, prelude_1.isntUndefined)(result)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
24
21
|
else {
|
|
25
|
-
const result = this.store.
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const result = this.store.get(key);
|
|
23
|
+
if (result) {
|
|
24
|
+
this.cache.set(key, result);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.cache.set(key, false);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
get(key) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
const result = this.cache.get(key);
|
|
35
|
+
if (result === false) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
else if ((0, prelude_1.isntUndefined)(result)) {
|
|
34
39
|
return result;
|
|
35
40
|
}
|
|
36
41
|
else {
|
|
37
42
|
const result = this.store.get(key);
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
if (result) {
|
|
44
|
+
this.cache.set(key, result);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.cache.set(key, false);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
40
51
|
}
|
|
41
52
|
}
|
|
42
53
|
async set(key, value) {
|
|
43
|
-
var _a;
|
|
44
54
|
await this.store.set(key, value);
|
|
45
|
-
|
|
55
|
+
this.cache.delete(key);
|
|
46
56
|
}
|
|
47
57
|
async delete(key) {
|
|
48
58
|
await this.store.delete(key);
|
|
49
|
-
this.cache.delete(
|
|
50
|
-
this.cache.delete(createCacheKey(CacheKeyType.Value, key));
|
|
59
|
+
this.cache.delete(key);
|
|
51
60
|
}
|
|
52
61
|
async clear() {
|
|
53
62
|
await this.store.clear();
|
|
@@ -58,8 +67,4 @@ class DiskStoreWithCache {
|
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
exports.DiskStoreWithCache = DiskStoreWithCache;
|
|
61
|
-
function createCacheKey(type, key) {
|
|
62
|
-
return JSON.stringify([type, key]);
|
|
63
|
-
}
|
|
64
|
-
exports.createCacheKey = createCacheKey;
|
|
65
70
|
//# sourceMappingURL=disk-store-with-cache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disk-store-with-cache.js","sourceRoot":"","sources":["../src/disk-store-with-cache.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"disk-store-with-cache.js","sourceRoot":"","sources":["../src/disk-store-with-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAmD;AAUnD,MAAa,kBAAkB;IAC7B,YACU,KAAgB,EAChB,KAAa;QADb,UAAK,GAAL,KAAK,CAAW;QAChB,UAAK,GAAL,KAAK,CAAQ;IACpB,CAAC;IAEJ,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClC,IAAI,MAAM,KAAK,KAAK,EAAE;YACpB,OAAO,MAAM,CAAA;SACd;aAAM,IAAI,IAAA,uBAAa,EAAC,MAAM,CAAC,EAAE;YAChC,OAAO,IAAI,CAAA;SACZ;aAAM;YACL,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAClC,IAAI,MAAM,EAAE;gBACV,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;gBAC3B,OAAO,IAAI,CAAA;aACZ;iBAAM;gBACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;gBAC1B,OAAO,KAAK,CAAA;aACb;SACF;IACH,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClC,IAAI,MAAM,KAAK,KAAK,EAAE;YACpB,OAAO,SAA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 -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@blackglory/jest-matchers": "^0.5.0",
|
|
40
|
+
"@blackglory/structures": "^0.11.5",
|
|
40
41
|
"@commitlint/cli": "^17.3.0",
|
|
41
42
|
"@commitlint/config-conventional": "^17.3.0",
|
|
42
43
|
"@types/jest": "^29.2.4",
|