@extra-memoize/extra-disk-cache 0.6.0 → 0.6.3
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/lib/es2015/disk-cache.d.ts +2 -4
- package/lib/es2015/disk-cache.js +10 -5
- package/lib/es2015/disk-cache.js.map +1 -1
- package/lib/es2015/stale-if-error-async-disk-cache.d.ts +2 -4
- package/lib/es2015/stale-if-error-async-disk-cache.js +11 -6
- package/lib/es2015/stale-if-error-async-disk-cache.js.map +1 -1
- package/lib/es2015/stale-while-revalidate-and-stale-if-error-async-disk-cache.d.ts +2 -4
- package/lib/es2015/stale-while-revalidate-and-stale-if-error-async-disk-cache.js +12 -7
- package/lib/es2015/stale-while-revalidate-and-stale-if-error-async-disk-cache.js.map +1 -1
- package/lib/es2015/stale-while-revalidate-async-disk-cache.d.ts +2 -4
- package/lib/es2015/stale-while-revalidate-async-disk-cache.js +11 -6
- package/lib/es2015/stale-while-revalidate-async-disk-cache.js.map +1 -1
- package/lib/es2018/disk-cache.d.ts +2 -4
- package/lib/es2018/disk-cache.js +10 -5
- package/lib/es2018/disk-cache.js.map +1 -1
- package/lib/es2018/stale-if-error-async-disk-cache.d.ts +2 -4
- package/lib/es2018/stale-if-error-async-disk-cache.js +11 -6
- package/lib/es2018/stale-if-error-async-disk-cache.js.map +1 -1
- package/lib/es2018/stale-while-revalidate-and-stale-if-error-async-disk-cache.d.ts +2 -4
- package/lib/es2018/stale-while-revalidate-and-stale-if-error-async-disk-cache.js +12 -7
- package/lib/es2018/stale-while-revalidate-and-stale-if-error-async-disk-cache.js.map +1 -1
- package/lib/es2018/stale-while-revalidate-async-disk-cache.d.ts +2 -4
- package/lib/es2018/stale-while-revalidate-async-disk-cache.js +11 -6
- package/lib/es2018/stale-while-revalidate-async-disk-cache.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ICache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache as ExtraDiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache as ExtraDiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class DiskCache<T> implements ICache<T> {
|
|
5
|
-
|
|
6
|
-
private toBuffer;
|
|
7
|
-
private fromBuffer;
|
|
5
|
+
cache: DiskCacheView<string, T>;
|
|
8
6
|
constructor(cache: ExtraDiskCache, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
9
7
|
get(key: string): [State.Miss] | [State.Hit, T];
|
|
10
8
|
set(key: string, value: T): void;
|
package/lib/es2015/disk-cache.js
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class DiskCache {
|
|
8
9
|
constructor(cache, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
11
|
+
toString: x => x,
|
|
12
|
+
fromString: x => x
|
|
13
|
+
}, {
|
|
14
|
+
toBuffer,
|
|
15
|
+
fromBuffer
|
|
16
|
+
});
|
|
12
17
|
}
|
|
13
18
|
get(key) {
|
|
14
19
|
const item = this.cache.get(key);
|
|
@@ -16,11 +21,11 @@ class DiskCache {
|
|
|
16
21
|
return [extra_memoize_1.State.Miss];
|
|
17
22
|
}
|
|
18
23
|
else {
|
|
19
|
-
return [extra_memoize_1.State.Hit,
|
|
24
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
set(key, value) {
|
|
23
|
-
this.cache.set(key,
|
|
28
|
+
this.cache.set(key, value, Date.now());
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
exports.DiskCache = DiskCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disk-cache.js","sourceRoot":"","sources":["../../src/disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;
|
|
1
|
+
{"version":3,"file":"disk-cache.js","sourceRoot":"","sources":["../../src/disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,uDAA6E;AAC7E,iDAAiD;AACjD,mCAA4D;AAE5D,MAAa,SAAS;IAGpB,YACE,KAAqB,EACrB,WAAiC,uBAAe,EAChD,aAAoC,yBAAiB;QAErD,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAa,CAC5B,KAAK,EACL;YACE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAChB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;SACnB,EACD;YACE,QAAQ;YACR,UAAU;SACX,CACF,CAAA;IACH,CAAC;IAED,GAAG,CAAC,GAAW;QAGb,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAChC,IAAI,IAAA,qBAAW,EAAC,IAAI,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;SAC/B;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IACxC,CAAC;CACF;AAnCD,8BAmCC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IStaleIfErrorCache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class StaleIfErrorDiskCache<T> implements IStaleIfErrorCache<T> {
|
|
5
|
-
private cache;
|
|
6
5
|
private timeToLive;
|
|
7
6
|
private staleIfError;
|
|
8
|
-
|
|
9
|
-
private fromBuffer;
|
|
7
|
+
cache: DiskCacheView<string, T>;
|
|
10
8
|
constructor(cache: DiskCache, timeToLive: number, staleIfError: number, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
11
9
|
get(key: string): [State.Miss] | [State.Hit | State.StaleIfError, T];
|
|
12
10
|
set(key: string, value: T): void;
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StaleIfErrorDiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class StaleIfErrorDiskCache {
|
|
8
9
|
constructor(cache, timeToLive, staleIfError, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache;
|
|
10
10
|
this.timeToLive = timeToLive;
|
|
11
11
|
this.staleIfError = staleIfError;
|
|
12
|
-
this.
|
|
13
|
-
|
|
12
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
13
|
+
toString: x => x,
|
|
14
|
+
fromString: x => x
|
|
15
|
+
}, {
|
|
16
|
+
toBuffer,
|
|
17
|
+
fromBuffer
|
|
18
|
+
});
|
|
14
19
|
}
|
|
15
20
|
get(key) {
|
|
16
21
|
const item = this.cache.get(key);
|
|
@@ -20,10 +25,10 @@ class StaleIfErrorDiskCache {
|
|
|
20
25
|
else {
|
|
21
26
|
const elapsed = Date.now() - item.updatedAt;
|
|
22
27
|
if (elapsed <= this.timeToLive) {
|
|
23
|
-
return [extra_memoize_1.State.Hit,
|
|
28
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
24
29
|
}
|
|
25
30
|
else if (elapsed <= this.timeToLive + this.staleIfError) {
|
|
26
|
-
return [extra_memoize_1.State.StaleIfError,
|
|
31
|
+
return [extra_memoize_1.State.StaleIfError, item.value];
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
34
|
return [extra_memoize_1.State.Miss];
|
|
@@ -31,7 +36,7 @@ class StaleIfErrorDiskCache {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
set(key, value) {
|
|
34
|
-
this.cache.set(key,
|
|
39
|
+
this.cache.set(key, value, Date.now(), this.timeToLive + this.staleIfError);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
exports.StaleIfErrorDiskCache = StaleIfErrorDiskCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-if-error-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAyD;
|
|
1
|
+
{"version":3,"file":"stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-if-error-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAyD;AACzD,uDAA2D;AAC3D,iDAAiD;AACjD,mCAA4D;AAE5D,MAAa,qBAAqB;IAGhC,YACE,KAAgB,EACR,UAAkB,EAClB,YAAoB,EAC5B,WAAiC,uBAAe,EAChD,aAAoC,yBAAiB;QAH7C,eAAU,GAAV,UAAU,CAAQ;QAClB,iBAAY,GAAZ,YAAY,CAAQ;QAI5B,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAa,CAC5B,KAAK,EACL;YACE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAChB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;SACnB,EACD;YACE,QAAQ;YACR,UAAU;SACX,CACF,CAAA;IACH,CAAC;IAED,GAAG,CAAC,GAAW;QAGb,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAChC,IAAI,IAAA,qBAAW,EAAC,IAAI,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAA;YAC3C,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,EAAE;gBAC9B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;aAC/B;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACzD,OAAO,CAAC,qBAAK,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;aACxC;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CACZ,GAAG,EACH,KAAK,EACL,IAAI,CAAC,GAAG,EAAE,EACV,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,CACpC,CAAA;IACH,CAAC;CACF;AAlDD,sDAkDC"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IStaleWhileRevalidateAndStaleIfErrorCache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class StaleWhileRevalidateAndStaleIfErrorDiskCache<T> implements IStaleWhileRevalidateAndStaleIfErrorCache<T> {
|
|
5
|
-
private cache;
|
|
6
5
|
private timeToLive;
|
|
7
6
|
private staleWhileRevalidate;
|
|
8
7
|
private staleIfError;
|
|
9
|
-
|
|
10
|
-
private fromBuffer;
|
|
8
|
+
cache: DiskCacheView<string, T>;
|
|
11
9
|
constructor(cache: DiskCache, timeToLive: number, staleWhileRevalidate: number, staleIfError: number, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
12
10
|
get(key: string): [State.Miss] | [State.Hit | State.StaleWhileRevalidate | State.StaleIfError, T];
|
|
13
11
|
set(key: string, value: T): void;
|
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StaleWhileRevalidateAndStaleIfErrorDiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class StaleWhileRevalidateAndStaleIfErrorDiskCache {
|
|
8
9
|
constructor(cache, timeToLive, staleWhileRevalidate, staleIfError, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache;
|
|
10
10
|
this.timeToLive = timeToLive;
|
|
11
11
|
this.staleWhileRevalidate = staleWhileRevalidate;
|
|
12
12
|
this.staleIfError = staleIfError;
|
|
13
|
-
this.
|
|
14
|
-
|
|
13
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
14
|
+
toString: x => x,
|
|
15
|
+
fromString: x => x
|
|
16
|
+
}, {
|
|
17
|
+
toBuffer,
|
|
18
|
+
fromBuffer
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
21
|
get(key) {
|
|
17
22
|
const item = this.cache.get(key);
|
|
@@ -21,13 +26,13 @@ class StaleWhileRevalidateAndStaleIfErrorDiskCache {
|
|
|
21
26
|
else {
|
|
22
27
|
const elapsed = Date.now() - item.updatedAt;
|
|
23
28
|
if (elapsed <= this.timeToLive) {
|
|
24
|
-
return [extra_memoize_1.State.Hit,
|
|
29
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
25
30
|
}
|
|
26
31
|
else if (elapsed <= this.timeToLive + this.staleWhileRevalidate) {
|
|
27
|
-
return [extra_memoize_1.State.StaleWhileRevalidate,
|
|
32
|
+
return [extra_memoize_1.State.StaleWhileRevalidate, item.value];
|
|
28
33
|
}
|
|
29
34
|
else if (elapsed <= this.timeToLive + this.staleWhileRevalidate + this.staleIfError) {
|
|
30
|
-
return [extra_memoize_1.State.StaleIfError,
|
|
35
|
+
return [extra_memoize_1.State.StaleIfError, item.value];
|
|
31
36
|
}
|
|
32
37
|
else {
|
|
33
38
|
return [extra_memoize_1.State.Miss];
|
|
@@ -35,7 +40,7 @@ class StaleWhileRevalidateAndStaleIfErrorDiskCache {
|
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
set(key, value) {
|
|
38
|
-
this.cache.set(key,
|
|
43
|
+
this.cache.set(key, value, Date.now(), this.timeToLive + this.staleWhileRevalidate + this.staleIfError);
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
exports.StaleWhileRevalidateAndStaleIfErrorDiskCache = StaleWhileRevalidateAndStaleIfErrorDiskCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stale-while-revalidate-and-stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-and-stale-if-error-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAgF;
|
|
1
|
+
{"version":3,"file":"stale-while-revalidate-and-stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-and-stale-if-error-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAgF;AAChF,uDAA2D;AAC3D,iDAAiD;AACjD,mCAA4D;AAE5D,MAAa,4CAA4C;IAGvD,YACE,KAAgB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;SACF;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CACZ,GAAG,EACH,KAAK,EACL,IAAI,CAAC,GAAG,EAAE,EACV,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,YAAY,CAChE,CAAA;IACH,CAAC;CACF;AArDD,oGAqDC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IStaleWhileRevalidateCache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class StaleWhileRevalidateDiskCache<T> implements IStaleWhileRevalidateCache<T> {
|
|
5
|
-
private cache;
|
|
6
5
|
private timeToLive;
|
|
7
6
|
private staleWhileRevalidate;
|
|
8
|
-
|
|
9
|
-
private fromBuffer;
|
|
7
|
+
cache: DiskCacheView<string, T>;
|
|
10
8
|
constructor(cache: DiskCache, timeToLive: number, staleWhileRevalidate: number, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
11
9
|
get(key: string): [State.Miss] | [State.Hit | State.StaleWhileRevalidate, T];
|
|
12
10
|
set(key: string, value: T): void;
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StaleWhileRevalidateDiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class StaleWhileRevalidateDiskCache {
|
|
8
9
|
constructor(cache, timeToLive, staleWhileRevalidate, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache;
|
|
10
10
|
this.timeToLive = timeToLive;
|
|
11
11
|
this.staleWhileRevalidate = staleWhileRevalidate;
|
|
12
|
-
this.
|
|
13
|
-
|
|
12
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
13
|
+
toString: x => x,
|
|
14
|
+
fromString: x => x
|
|
15
|
+
}, {
|
|
16
|
+
toBuffer,
|
|
17
|
+
fromBuffer
|
|
18
|
+
});
|
|
14
19
|
}
|
|
15
20
|
get(key) {
|
|
16
21
|
const item = this.cache.get(key);
|
|
@@ -19,15 +24,15 @@ class StaleWhileRevalidateDiskCache {
|
|
|
19
24
|
}
|
|
20
25
|
else {
|
|
21
26
|
if (this.isStaleWhileRevalidate(item.updatedAt)) {
|
|
22
|
-
return [extra_memoize_1.State.StaleWhileRevalidate,
|
|
27
|
+
return [extra_memoize_1.State.StaleWhileRevalidate, item.value];
|
|
23
28
|
}
|
|
24
29
|
else {
|
|
25
|
-
return [extra_memoize_1.State.Hit,
|
|
30
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
set(key, value) {
|
|
30
|
-
this.cache.set(key,
|
|
35
|
+
this.cache.set(key, value, Date.now(), this.timeToLive + this.staleWhileRevalidate);
|
|
31
36
|
}
|
|
32
37
|
isStaleWhileRevalidate(updatedAt) {
|
|
33
38
|
const elapsed = Date.now() - updatedAt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stale-while-revalidate-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;
|
|
1
|
+
{"version":3,"file":"stale-while-revalidate-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;AACjE,uDAA2D;AAC3D,iDAAiD;AACjD,mCAA4D;AAE5D,MAAa,6BAA6B;IAGxC,YACE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A;IAC9D,CAAC;CACF;AApDD,sEAoDC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ICache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache as ExtraDiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache as ExtraDiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class DiskCache<T> implements ICache<T> {
|
|
5
|
-
|
|
6
|
-
private toBuffer;
|
|
7
|
-
private fromBuffer;
|
|
5
|
+
cache: DiskCacheView<string, T>;
|
|
8
6
|
constructor(cache: ExtraDiskCache, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
9
7
|
get(key: string): [State.Miss] | [State.Hit, T];
|
|
10
8
|
set(key: string, value: T): void;
|
package/lib/es2018/disk-cache.js
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class DiskCache {
|
|
8
9
|
constructor(cache, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
11
|
+
toString: x => x,
|
|
12
|
+
fromString: x => x
|
|
13
|
+
}, {
|
|
14
|
+
toBuffer,
|
|
15
|
+
fromBuffer
|
|
16
|
+
});
|
|
12
17
|
}
|
|
13
18
|
get(key) {
|
|
14
19
|
const item = this.cache.get(key);
|
|
@@ -16,11 +21,11 @@ class DiskCache {
|
|
|
16
21
|
return [extra_memoize_1.State.Miss];
|
|
17
22
|
}
|
|
18
23
|
else {
|
|
19
|
-
return [extra_memoize_1.State.Hit,
|
|
24
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
set(key, value) {
|
|
23
|
-
this.cache.set(key,
|
|
28
|
+
this.cache.set(key, value, Date.now());
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
exports.DiskCache = DiskCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"disk-cache.js","sourceRoot":"","sources":["../../src/disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;
|
|
1
|
+
{"version":3,"file":"disk-cache.js","sourceRoot":"","sources":["../../src/disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,uDAA6E;AAC7E,iDAAiD;AACjD,mCAA4D;AAE5D,MAAa,SAAS;IAGpB,YACE,KAAqB,EACrB,WAAiC,uBAAe,EAChD,aAAoC,yBAAiB;QAErD,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAa,CAC5B,KAAK,EACL;YACE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAChB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;SACnB,EACD;YACE,QAAQ;YACR,UAAU;SACX,CACF,CAAA;IACH,CAAC;IAED,GAAG,CAAC,GAAW;QAGb,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAChC,IAAI,IAAA,qBAAW,EAAC,IAAI,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;SAC/B;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IACxC,CAAC;CACF;AAnCD,8BAmCC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IStaleIfErrorCache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class StaleIfErrorDiskCache<T> implements IStaleIfErrorCache<T> {
|
|
5
|
-
private cache;
|
|
6
5
|
private timeToLive;
|
|
7
6
|
private staleIfError;
|
|
8
|
-
|
|
9
|
-
private fromBuffer;
|
|
7
|
+
cache: DiskCacheView<string, T>;
|
|
10
8
|
constructor(cache: DiskCache, timeToLive: number, staleIfError: number, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
11
9
|
get(key: string): [State.Miss] | [State.Hit | State.StaleIfError, T];
|
|
12
10
|
set(key: string, value: T): void;
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StaleIfErrorDiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class StaleIfErrorDiskCache {
|
|
8
9
|
constructor(cache, timeToLive, staleIfError, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache;
|
|
10
10
|
this.timeToLive = timeToLive;
|
|
11
11
|
this.staleIfError = staleIfError;
|
|
12
|
-
this.
|
|
13
|
-
|
|
12
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
13
|
+
toString: x => x,
|
|
14
|
+
fromString: x => x
|
|
15
|
+
}, {
|
|
16
|
+
toBuffer,
|
|
17
|
+
fromBuffer
|
|
18
|
+
});
|
|
14
19
|
}
|
|
15
20
|
get(key) {
|
|
16
21
|
const item = this.cache.get(key);
|
|
@@ -20,10 +25,10 @@ class StaleIfErrorDiskCache {
|
|
|
20
25
|
else {
|
|
21
26
|
const elapsed = Date.now() - item.updatedAt;
|
|
22
27
|
if (elapsed <= this.timeToLive) {
|
|
23
|
-
return [extra_memoize_1.State.Hit,
|
|
28
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
24
29
|
}
|
|
25
30
|
else if (elapsed <= this.timeToLive + this.staleIfError) {
|
|
26
|
-
return [extra_memoize_1.State.StaleIfError,
|
|
31
|
+
return [extra_memoize_1.State.StaleIfError, item.value];
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
34
|
return [extra_memoize_1.State.Miss];
|
|
@@ -31,7 +36,7 @@ class StaleIfErrorDiskCache {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
set(key, value) {
|
|
34
|
-
this.cache.set(key,
|
|
39
|
+
this.cache.set(key, value, Date.now(), this.timeToLive + this.staleIfError);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
exports.StaleIfErrorDiskCache = StaleIfErrorDiskCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-if-error-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAyD;
|
|
1
|
+
{"version":3,"file":"stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-if-error-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAyD;AACzD,uDAA2D;AAC3D,iDAAiD;AACjD,mCAA4D;AAE5D,MAAa,qBAAqB;IAGhC,YACE,KAAgB,EACR,UAAkB,EAClB,YAAoB,EAC5B,WAAiC,uBAAe,EAChD,aAAoC,yBAAiB;QAH7C,eAAU,GAAV,UAAU,CAAQ;QAClB,iBAAY,GAAZ,YAAY,CAAQ;QAI5B,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAa,CAC5B,KAAK,EACL;YACE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAChB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;SACnB,EACD;YACE,QAAQ;YACR,UAAU;SACX,CACF,CAAA;IACH,CAAC;IAED,GAAG,CAAC,GAAW;QAGb,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAChC,IAAI,IAAA,qBAAW,EAAC,IAAI,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAA;YAC3C,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,EAAE;gBAC9B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;aAC/B;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACzD,OAAO,CAAC,qBAAK,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;aACxC;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CACZ,GAAG,EACH,KAAK,EACL,IAAI,CAAC,GAAG,EAAE,EACV,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,CACpC,CAAA;IACH,CAAC;CACF;AAlDD,sDAkDC"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IStaleWhileRevalidateAndStaleIfErrorCache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class StaleWhileRevalidateAndStaleIfErrorDiskCache<T> implements IStaleWhileRevalidateAndStaleIfErrorCache<T> {
|
|
5
|
-
private cache;
|
|
6
5
|
private timeToLive;
|
|
7
6
|
private staleWhileRevalidate;
|
|
8
7
|
private staleIfError;
|
|
9
|
-
|
|
10
|
-
private fromBuffer;
|
|
8
|
+
cache: DiskCacheView<string, T>;
|
|
11
9
|
constructor(cache: DiskCache, timeToLive: number, staleWhileRevalidate: number, staleIfError: number, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
12
10
|
get(key: string): [State.Miss] | [State.Hit | State.StaleWhileRevalidate | State.StaleIfError, T];
|
|
13
11
|
set(key: string, value: T): void;
|
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StaleWhileRevalidateAndStaleIfErrorDiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class StaleWhileRevalidateAndStaleIfErrorDiskCache {
|
|
8
9
|
constructor(cache, timeToLive, staleWhileRevalidate, staleIfError, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache;
|
|
10
10
|
this.timeToLive = timeToLive;
|
|
11
11
|
this.staleWhileRevalidate = staleWhileRevalidate;
|
|
12
12
|
this.staleIfError = staleIfError;
|
|
13
|
-
this.
|
|
14
|
-
|
|
13
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
14
|
+
toString: x => x,
|
|
15
|
+
fromString: x => x
|
|
16
|
+
}, {
|
|
17
|
+
toBuffer,
|
|
18
|
+
fromBuffer
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
21
|
get(key) {
|
|
17
22
|
const item = this.cache.get(key);
|
|
@@ -21,13 +26,13 @@ class StaleWhileRevalidateAndStaleIfErrorDiskCache {
|
|
|
21
26
|
else {
|
|
22
27
|
const elapsed = Date.now() - item.updatedAt;
|
|
23
28
|
if (elapsed <= this.timeToLive) {
|
|
24
|
-
return [extra_memoize_1.State.Hit,
|
|
29
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
25
30
|
}
|
|
26
31
|
else if (elapsed <= this.timeToLive + this.staleWhileRevalidate) {
|
|
27
|
-
return [extra_memoize_1.State.StaleWhileRevalidate,
|
|
32
|
+
return [extra_memoize_1.State.StaleWhileRevalidate, item.value];
|
|
28
33
|
}
|
|
29
34
|
else if (elapsed <= this.timeToLive + this.staleWhileRevalidate + this.staleIfError) {
|
|
30
|
-
return [extra_memoize_1.State.StaleIfError,
|
|
35
|
+
return [extra_memoize_1.State.StaleIfError, item.value];
|
|
31
36
|
}
|
|
32
37
|
else {
|
|
33
38
|
return [extra_memoize_1.State.Miss];
|
|
@@ -35,7 +40,7 @@ class StaleWhileRevalidateAndStaleIfErrorDiskCache {
|
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
set(key, value) {
|
|
38
|
-
this.cache.set(key,
|
|
43
|
+
this.cache.set(key, value, Date.now(), this.timeToLive + this.staleWhileRevalidate + this.staleIfError);
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
exports.StaleWhileRevalidateAndStaleIfErrorDiskCache = StaleWhileRevalidateAndStaleIfErrorDiskCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stale-while-revalidate-and-stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-and-stale-if-error-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAgF;
|
|
1
|
+
{"version":3,"file":"stale-while-revalidate-and-stale-if-error-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-and-stale-if-error-async-disk-c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AAK,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;aACxC;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CACZ,GAAG,EACH,KAAK,EACL,IAAI,CAAC,GAAG,EAAE,EACV,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,YAAY,CAChE,CAAA;IACH,CAAC;CACF;AArDD,oGAqDC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IStaleWhileRevalidateCache, State } from 'extra-memoize';
|
|
3
|
-
import { DiskCache } from 'extra-disk-cache';
|
|
3
|
+
import { DiskCache, DiskCacheView } from 'extra-disk-cache';
|
|
4
4
|
export declare class StaleWhileRevalidateDiskCache<T> implements IStaleWhileRevalidateCache<T> {
|
|
5
|
-
private cache;
|
|
6
5
|
private timeToLive;
|
|
7
6
|
private staleWhileRevalidate;
|
|
8
|
-
|
|
9
|
-
private fromBuffer;
|
|
7
|
+
cache: DiskCacheView<string, T>;
|
|
10
8
|
constructor(cache: DiskCache, timeToLive: number, staleWhileRevalidate: number, toBuffer?: (value: T) => Buffer, fromBuffer?: (buffer: Buffer) => T);
|
|
11
9
|
get(key: string): [State.Miss] | [State.Hit | State.StaleWhileRevalidate, T];
|
|
12
10
|
set(key: string, value: T): void;
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StaleWhileRevalidateDiskCache = void 0;
|
|
4
4
|
const extra_memoize_1 = require("extra-memoize");
|
|
5
|
+
const extra_disk_cache_1 = require("extra-disk-cache");
|
|
5
6
|
const prelude_1 = require("@blackglory/prelude");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
class StaleWhileRevalidateDiskCache {
|
|
8
9
|
constructor(cache, timeToLive, staleWhileRevalidate, toBuffer = utils_1.defaultToBuffer, fromBuffer = utils_1.defaultFromBuffer) {
|
|
9
|
-
this.cache = cache;
|
|
10
10
|
this.timeToLive = timeToLive;
|
|
11
11
|
this.staleWhileRevalidate = staleWhileRevalidate;
|
|
12
|
-
this.
|
|
13
|
-
|
|
12
|
+
this.cache = new extra_disk_cache_1.DiskCacheView(cache, {
|
|
13
|
+
toString: x => x,
|
|
14
|
+
fromString: x => x
|
|
15
|
+
}, {
|
|
16
|
+
toBuffer,
|
|
17
|
+
fromBuffer
|
|
18
|
+
});
|
|
14
19
|
}
|
|
15
20
|
get(key) {
|
|
16
21
|
const item = this.cache.get(key);
|
|
@@ -19,15 +24,15 @@ class StaleWhileRevalidateDiskCache {
|
|
|
19
24
|
}
|
|
20
25
|
else {
|
|
21
26
|
if (this.isStaleWhileRevalidate(item.updatedAt)) {
|
|
22
|
-
return [extra_memoize_1.State.StaleWhileRevalidate,
|
|
27
|
+
return [extra_memoize_1.State.StaleWhileRevalidate, item.value];
|
|
23
28
|
}
|
|
24
29
|
else {
|
|
25
|
-
return [extra_memoize_1.State.Hit,
|
|
30
|
+
return [extra_memoize_1.State.Hit, item.value];
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
set(key, value) {
|
|
30
|
-
this.cache.set(key,
|
|
35
|
+
this.cache.set(key, value, Date.now(), this.timeToLive + this.staleWhileRevalidate);
|
|
31
36
|
}
|
|
32
37
|
isStaleWhileRevalidate(updatedAt) {
|
|
33
38
|
const elapsed = Date.now() - updatedAt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stale-while-revalidate-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-async-disk-cache.ts"],"names":[],"mappings":";;;AAAA,iDAAiE;
|
|
1
|
+
{"version":3,"file":"stale-while-revalidate-async-disk-cache.js","sourceRoot":"","sources":["../../src/stale-while-revalidate-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,SAAS,CAAA;QACtC,OAAO,OAAO,GAAG,IAAI,CAAC,UAAU;eACzB,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAA;IAC9D,CAAC;CACF;AApDD,sEAoDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extra-memoize/extra-disk-cache",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib"
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"@commitlint/cli": "^17.0.3",
|
|
40
40
|
"@commitlint/config-conventional": "^17.0.3",
|
|
41
41
|
"@types/jest": "^27.5.1",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
43
|
-
"@typescript-eslint/parser": "^5.
|
|
44
|
-
"eslint": "^8.
|
|
45
|
-
"extra-disk-cache": "^0.
|
|
46
|
-
"extra-memoize": "^0.
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
|
43
|
+
"@typescript-eslint/parser": "^5.32.0",
|
|
44
|
+
"eslint": "^8.21.0",
|
|
45
|
+
"extra-disk-cache": "^0.8.1",
|
|
46
|
+
"extra-memoize": "^0.8.0",
|
|
47
47
|
"husky": "^4.3.8",
|
|
48
48
|
"jest": "^28.1.3",
|
|
49
49
|
"npm-run-all": "^4.1.5",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@blackglory/prelude": "^0.1.3"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"extra-disk-cache": "^0.7.0",
|
|
63
|
-
"extra-memoize": "^0.6.0 || ^0.7.0"
|
|
62
|
+
"extra-disk-cache": "^0.7.0 || ^0.8.0",
|
|
63
|
+
"extra-memoize": "^0.6.0 || ^0.7.0 || ^0.8.0"
|
|
64
64
|
}
|
|
65
65
|
}
|