@extra-memoize/memory-cache 0.2.11 → 0.3.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/lib/caches/cache.js +24 -0
- package/lib/caches/cache.js.map +1 -0
- package/lib/caches/expirable-cache-with-stale-if-error.js +35 -0
- package/lib/caches/expirable-cache-with-stale-if-error.js.map +1 -0
- package/lib/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js +39 -0
- package/lib/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map +1 -0
- package/lib/{es2018/caches → caches}/expirable-cache-with-stale-while-revalidate.js +8 -12
- package/lib/caches/expirable-cache-with-stale-while-revalidate.js.map +1 -0
- package/lib/caches/expirable-cache.js +23 -0
- package/lib/caches/expirable-cache.js.map +1 -0
- package/lib/caches/index.d.ts +10 -0
- package/lib/caches/index.js +11 -0
- package/lib/caches/index.js.map +1 -0
- package/lib/caches/lru-cache.js +22 -0
- package/lib/caches/lru-cache.js.map +1 -0
- package/lib/caches/tlru-cache-with-stale-if-error.js +35 -0
- package/lib/caches/tlru-cache-with-stale-if-error.js.map +1 -0
- package/lib/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js +39 -0
- package/lib/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js.map +1 -0
- package/lib/{es2018/caches → caches}/tlru-cache-with-stale-while-revalidate.js +8 -12
- package/lib/caches/tlru-cache-with-stale-while-revalidate.js.map +1 -0
- package/lib/caches/tlru-cache.js +23 -0
- package/lib/caches/tlru-cache.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/package.json +33 -35
- package/src/caches/expirable-cache-with-stale-if-error.ts +4 -4
- package/src/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.ts +5 -5
- package/src/caches/expirable-cache-with-stale-while-revalidate.ts +1 -1
- package/src/caches/index.ts +10 -10
- package/src/caches/tlru-cache-with-stale-if-error.ts +4 -4
- package/src/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.ts +5 -5
- package/src/caches/tlru-cache-with-stale-while-revalidate.ts +1 -1
- package/src/index.ts +1 -1
- package/lib/es2015/caches/cache.js +0 -28
- package/lib/es2015/caches/cache.js.map +0 -1
- package/lib/es2015/caches/expirable-cache-with-stale-if-error.js +0 -38
- package/lib/es2015/caches/expirable-cache-with-stale-if-error.js.map +0 -1
- package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
- package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
- package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate.js +0 -39
- package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate.js.map +0 -1
- package/lib/es2015/caches/expirable-cache.js +0 -27
- package/lib/es2015/caches/expirable-cache.js.map +0 -1
- package/lib/es2015/caches/index.d.ts +0 -10
- package/lib/es2015/caches/index.js +0 -27
- package/lib/es2015/caches/index.js.map +0 -1
- package/lib/es2015/caches/lru-cache.js +0 -26
- package/lib/es2015/caches/lru-cache.js.map +0 -1
- package/lib/es2015/caches/tlru-cache-with-stale-if-error.js +0 -38
- package/lib/es2015/caches/tlru-cache-with-stale-if-error.js.map +0 -1
- package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
- package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
- package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate.js +0 -39
- package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate.js.map +0 -1
- package/lib/es2015/caches/tlru-cache.js +0 -27
- package/lib/es2015/caches/tlru-cache.js.map +0 -1
- package/lib/es2015/index.d.ts +0 -1
- package/lib/es2015/index.js +0 -18
- package/lib/es2015/index.js.map +0 -1
- package/lib/es2018/caches/cache.d.ts +0 -8
- package/lib/es2018/caches/cache.js +0 -28
- package/lib/es2018/caches/cache.js.map +0 -1
- package/lib/es2018/caches/expirable-cache-with-stale-if-error.d.ts +0 -9
- package/lib/es2018/caches/expirable-cache-with-stale-if-error.js +0 -38
- package/lib/es2018/caches/expirable-cache-with-stale-if-error.js.map +0 -1
- package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -13
- package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
- package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
- package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate.d.ts +0 -10
- package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate.js.map +0 -1
- package/lib/es2018/caches/expirable-cache.d.ts +0 -9
- package/lib/es2018/caches/expirable-cache.js +0 -27
- package/lib/es2018/caches/expirable-cache.js.map +0 -1
- package/lib/es2018/caches/index.d.ts +0 -10
- package/lib/es2018/caches/index.js +0 -27
- package/lib/es2018/caches/index.js.map +0 -1
- package/lib/es2018/caches/lru-cache.d.ts +0 -8
- package/lib/es2018/caches/lru-cache.js +0 -26
- package/lib/es2018/caches/lru-cache.js.map +0 -1
- package/lib/es2018/caches/tlru-cache-with-stale-if-error.d.ts +0 -9
- package/lib/es2018/caches/tlru-cache-with-stale-if-error.js +0 -38
- package/lib/es2018/caches/tlru-cache-with-stale-if-error.js.map +0 -1
- package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -13
- package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
- package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
- package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate.d.ts +0 -15
- package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate.js.map +0 -1
- package/lib/es2018/caches/tlru-cache.d.ts +0 -9
- package/lib/es2018/caches/tlru-cache.js +0 -27
- package/lib/es2018/caches/tlru-cache.js.map +0 -1
- package/lib/es2018/index.d.ts +0 -1
- package/lib/es2018/index.js +0 -18
- package/lib/es2018/index.js.map +0 -1
- /package/lib/{es2015/caches → caches}/cache.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/expirable-cache-with-stale-if-error.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/expirable-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/expirable-cache-with-stale-while-revalidate.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/expirable-cache.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/lru-cache.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/tlru-cache-with-stale-if-error.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/tlru-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/tlru-cache-with-stale-while-revalidate.d.ts +0 -0
- /package/lib/{es2015/caches → caches}/tlru-cache.d.ts +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
import { TLRUCache } from './tlru-cache'
|
1
|
+
import { TLRUCache } from './tlru-cache.js'
|
2
2
|
import { IStaleWhileRevalidateAndStaleIfErrorCache, State } from 'extra-memoize'
|
3
3
|
|
4
4
|
interface IRecord<T> {
|
@@ -36,12 +36,12 @@ export class TLRUCacheWithStaleWhileRevalidateAndStaleIfError<T> implements ISta
|
|
36
36
|
if (state === State.Miss) {
|
37
37
|
return [State.Miss]
|
38
38
|
} else {
|
39
|
-
const
|
40
|
-
if (
|
39
|
+
const timestamp = Date.now()
|
40
|
+
if (record.updatedAt + this.timeToLive > timestamp) {
|
41
41
|
return [State.Hit, record.value]
|
42
|
-
} else if (
|
42
|
+
} else if (record.updatedAt + this.timeToLive + this.staleWhileRevalidate > timestamp) {
|
43
43
|
return [State.StaleWhileRevalidate, record.value]
|
44
|
-
} else if (
|
44
|
+
} else if (record.updatedAt + this.timeToLive + this.staleWhileRevalidate + this.staleIfError > timestamp) {
|
45
45
|
return [State.StaleIfError, record.value]
|
46
46
|
} else {
|
47
47
|
// just in case
|
package/src/index.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from '@caches'
|
1
|
+
export * from '@caches/index.js'
|
@@ -1,28 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Cache = void 0;
|
4
|
-
const extra_memoize_1 = require("extra-memoize");
|
5
|
-
class Cache {
|
6
|
-
constructor() {
|
7
|
-
this.map = new Map();
|
8
|
-
}
|
9
|
-
set(key, value) {
|
10
|
-
this.map.set(key, value);
|
11
|
-
}
|
12
|
-
get(key) {
|
13
|
-
if (this.map.has(key)) {
|
14
|
-
return [extra_memoize_1.State.Hit, this.map.get(key)];
|
15
|
-
}
|
16
|
-
else {
|
17
|
-
return [extra_memoize_1.State.Miss];
|
18
|
-
}
|
19
|
-
}
|
20
|
-
delete(key) {
|
21
|
-
this.map.delete(key);
|
22
|
-
}
|
23
|
-
clear() {
|
24
|
-
this.map.clear();
|
25
|
-
}
|
26
|
-
}
|
27
|
-
exports.Cache = Cache;
|
28
|
-
//# sourceMappingURL=cache.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/caches/cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,KAAK;IAAlB;QACU,QAAG,GAAG,IAAI,GAAG,EAAE,CAAA;IAqBzB,CAAC;IAnBC,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;SACtC;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;IACH,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF;AAtBD,sBAsBC"}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ExpirableCacheWithStaleIfError = void 0;
|
4
|
-
const expirable_cache_1 = require("./expirable-cache");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class ExpirableCacheWithStaleIfError {
|
7
|
-
constructor(timeToLive, staleIfError) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.staleIfError = staleIfError;
|
10
|
-
this.cache = new expirable_cache_1.ExpirableCache(timeToLive + staleIfError);
|
11
|
-
}
|
12
|
-
set(key, value) {
|
13
|
-
this.cache.set(key, {
|
14
|
-
value,
|
15
|
-
updatedAt: Date.now()
|
16
|
-
});
|
17
|
-
}
|
18
|
-
get(key) {
|
19
|
-
const [state, record] = this.cache.get(key);
|
20
|
-
if (state === extra_memoize_1.State.Miss) {
|
21
|
-
return [extra_memoize_1.State.Miss];
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
const elapsed = Date.now() - record.updatedAt;
|
25
|
-
if (elapsed < this.timeToLive) {
|
26
|
-
return [extra_memoize_1.State.Hit, record.value];
|
27
|
-
}
|
28
|
-
else if (elapsed < this.timeToLive + this.staleIfError) {
|
29
|
-
return [extra_memoize_1.State.StaleIfError, record.value];
|
30
|
-
}
|
31
|
-
else {
|
32
|
-
return [extra_memoize_1.State.Miss];
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
exports.ExpirableCacheWithStaleIfError = ExpirableCacheWithStaleIfError;
|
38
|
-
//# sourceMappingURL=expirable-cache-with-stale-if-error.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"expirable-cache-with-stale-if-error.js","sourceRoot":"","sources":["../../../src/caches/expirable-cache-with-stale-if-error.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAClD,iDAAyD;AAOzD,MAAa,8BAA8B;IAGzC,YAAoB,UAAkB,EAAU,YAAoB;QAAhD,eAAU,GAAV,UAAU,CAAQ;QAAU,iBAAY,GAAZ,YAAY,CAAQ;QAClE,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAc,CAAC,UAAU,GAAG,YAAY,CAAC,CAAA;IAC5D,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,KAAK,KAAK,qBAAK,CAAC,IAAI,EAAE;YACxB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,CAAA;YAC7C,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE;gBAC7B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACxD,OAAO,CAAC,qBAAK,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAC1C;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;CACF;AA9BD,wEA8BC"}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ExpirableCacheWithStaleWhileRevalidateAndStaleIfError = void 0;
|
4
|
-
const expirable_cache_1 = require("./expirable-cache");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class ExpirableCacheWithStaleWhileRevalidateAndStaleIfError {
|
7
|
-
constructor(timeToLive, staleWhileRevalidate, staleIfError) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.staleWhileRevalidate = staleWhileRevalidate;
|
10
|
-
this.staleIfError = staleIfError;
|
11
|
-
this.cache = new expirable_cache_1.ExpirableCache(timeToLive + staleWhileRevalidate + staleIfError);
|
12
|
-
}
|
13
|
-
set(key, value) {
|
14
|
-
this.cache.set(key, {
|
15
|
-
value,
|
16
|
-
updatedAt: Date.now()
|
17
|
-
});
|
18
|
-
}
|
19
|
-
get(key) {
|
20
|
-
const [state, record] = this.cache.get(key);
|
21
|
-
if (state === extra_memoize_1.State.Miss) {
|
22
|
-
return [extra_memoize_1.State.Miss];
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
const elapsed = Date.now() - record.updatedAt;
|
26
|
-
if (elapsed < this.timeToLive) {
|
27
|
-
return [extra_memoize_1.State.Hit, record.value];
|
28
|
-
}
|
29
|
-
else if (elapsed < this.timeToLive + this.staleWhileRevalidate) {
|
30
|
-
return [extra_memoize_1.State.StaleWhileRevalidate, record.value];
|
31
|
-
}
|
32
|
-
else if (elapsed < this.timeToLive + this.staleWhileRevalidate + this.staleIfError) {
|
33
|
-
return [extra_memoize_1.State.StaleIfError, record.value];
|
34
|
-
}
|
35
|
-
else {
|
36
|
-
return [extra_memoize_1.State.Miss];
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
}
|
41
|
-
exports.ExpirableCacheWithStaleWhileRevalidateAndStaleIfError = ExpirableCacheWithStaleWhileRevalidateAndStaleIfError;
|
42
|
-
//# sourceMappingURL=expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map
|
package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"expirable-cache-with-stale-while-revalidate-and-stale-if-error.js","sourceRoot":"","sources":["../../../src/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAClD,iDAAgF;AAOhF,MAAa,qDAAqD;IAGhE,YACU,UAAkB,EAClB,oBAA4B,EAC5B,YAAoB;QAFpB,eAAU,GAAV,UAAU,CAAQ;QAClB,yBAAoB,GAApB,oBAAoB,CAAQ;QAC5B,iBAAY,GAAZ,YAAY,CAAQ;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAc,CAAC,UAAU,GAAG,oBAAoB,GAAG,YAAY,CAAC,CAAA;IACnF,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QAOb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,KAAK,KAAK,qBAAK,CAAC,IAAI,EAAE;YACxB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,CAAA;YAC7C,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE;gBAC7B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,EAAE;gBAChE,OAAO,CAAC,qBAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAClD;iBAAM,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,YAAY,EAAE;gBACpF,OAAO,CAAC,qBAAK,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAC1C;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;CACF;AA1CD,sHA0CC"}
|
@@ -1,39 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ExpirableCacheWithStaleWhileRevalidate = void 0;
|
4
|
-
const expirable_cache_1 = require("./expirable-cache");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class ExpirableCacheWithStaleWhileRevalidate {
|
7
|
-
constructor(timeToLive, staleWhileRevalidate) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.staleWhileRevalidate = staleWhileRevalidate;
|
10
|
-
this.cache = new expirable_cache_1.ExpirableCache(timeToLive + staleWhileRevalidate);
|
11
|
-
}
|
12
|
-
set(key, value) {
|
13
|
-
this.cache.set(key, {
|
14
|
-
value,
|
15
|
-
updatedAt: Date.now()
|
16
|
-
});
|
17
|
-
}
|
18
|
-
get(key) {
|
19
|
-
const [state, record] = this.cache.get(key);
|
20
|
-
if (state === extra_memoize_1.State.Miss) {
|
21
|
-
return [extra_memoize_1.State.Miss];
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
if (this.isStaleWhileRevalidate(record)) {
|
25
|
-
return [extra_memoize_1.State.StaleWhileRevalidate, record.value];
|
26
|
-
}
|
27
|
-
else {
|
28
|
-
return [extra_memoize_1.State.Hit, record.value];
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
isStaleWhileRevalidate(record) {
|
33
|
-
const timestamp = Date.now();
|
34
|
-
return record.updatedAt + this.timeToLive <= timestamp
|
35
|
-
&& record.updatedAt + this.timeToLive + this.staleWhileRevalidate > timestamp;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
exports.ExpirableCacheWithStaleWhileRevalidate = ExpirableCacheWithStaleWhileRevalidate;
|
39
|
-
//# sourceMappingURL=expirable-cache-with-stale-while-revalidate.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"expirable-cache-with-stale-while-revalidate.js","sourceRoot":"","sources":["../../../src/caches/expirable-cache-with-stale-while-revalidate.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAClD,iDAAiE;AAOjE,MAAa,sCAAsC;IAGjD,YAAoB,UAAkB,EAAU,oBAA4B;QAAxD,eAAU,GAAV,UAAU,CAAQ;QAAU,yBAAoB,GAApB,oBAAoB,CAAQ;QAC1E,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAc,CAAC,UAAU,GAAG,oBAAoB,CAAC,CAAA;IACpE,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,KAAK,KAAK,qBAAK,CAAC,IAAI,EAAE;YACxB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,IAAI,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE;gBACvC,OAAO,CAAC,qBAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAClD;iBAAM;gBACL,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;SACF;IACH,CAAC;IAEO,sBAAsB,CAAC,MAAkB;QAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC5B,OAAO,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,IAAI,SAAS;eAC/C,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAA;IACnF,CAAC;CACF;AAhCD,wFAgCC"}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ExpirableCache = void 0;
|
4
|
-
const structures_1 = require("@blackglory/structures");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class ExpirableCache {
|
7
|
-
constructor(timeToLive) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.map = new structures_1.ExpirableMap();
|
10
|
-
}
|
11
|
-
get(key) {
|
12
|
-
if (this.map.has(key)) {
|
13
|
-
return [extra_memoize_1.State.Hit, this.map.get(key)];
|
14
|
-
}
|
15
|
-
else {
|
16
|
-
return [extra_memoize_1.State.Miss];
|
17
|
-
}
|
18
|
-
}
|
19
|
-
set(key, value) {
|
20
|
-
this.map.set(key, value, this.timeToLive);
|
21
|
-
}
|
22
|
-
clear() {
|
23
|
-
this.map.clear();
|
24
|
-
}
|
25
|
-
}
|
26
|
-
exports.ExpirableCache = ExpirableCache;
|
27
|
-
//# sourceMappingURL=expirable-cache.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"expirable-cache.js","sourceRoot":"","sources":["../../../src/caches/expirable-cache.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AACrD,iDAA6C;AAE7C,MAAa,cAAc;IAGzB,YAAoB,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;QACpC,IAAI,CAAC,GAAG,GAAG,IAAI,yBAAY,EAAE,CAAA;IAC/B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAA;SACvC;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF;AAtBD,wCAsBC"}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
export * from './cache';
|
2
|
-
export * from './lru-cache';
|
3
|
-
export * from './expirable-cache';
|
4
|
-
export * from './expirable-cache-with-stale-while-revalidate';
|
5
|
-
export * from './expirable-cache-with-stale-if-error';
|
6
|
-
export * from './expirable-cache-with-stale-while-revalidate-and-stale-if-error';
|
7
|
-
export * from './tlru-cache';
|
8
|
-
export * from './tlru-cache-with-stale-while-revalidate';
|
9
|
-
export * from './tlru-cache-with-stale-if-error';
|
10
|
-
export * from './tlru-cache-with-stale-while-revalidate-and-stale-if-error';
|
@@ -1,27 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./cache"), exports);
|
18
|
-
__exportStar(require("./lru-cache"), exports);
|
19
|
-
__exportStar(require("./expirable-cache"), exports);
|
20
|
-
__exportStar(require("./expirable-cache-with-stale-while-revalidate"), exports);
|
21
|
-
__exportStar(require("./expirable-cache-with-stale-if-error"), exports);
|
22
|
-
__exportStar(require("./expirable-cache-with-stale-while-revalidate-and-stale-if-error"), exports);
|
23
|
-
__exportStar(require("./tlru-cache"), exports);
|
24
|
-
__exportStar(require("./tlru-cache-with-stale-while-revalidate"), exports);
|
25
|
-
__exportStar(require("./tlru-cache-with-stale-if-error"), exports);
|
26
|
-
__exportStar(require("./tlru-cache-with-stale-while-revalidate-and-stale-if-error"), exports);
|
27
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/caches/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AAEvB,8CAA2B;AAE3B,oDAAiC;AACjC,gFAA6D;AAC7D,wEAAqD;AACrD,mGAAgF;AAEhF,+CAA4B;AAC5B,2EAAwD;AACxD,mEAAgD;AAChD,8FAA2E"}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.LRUCache = void 0;
|
4
|
-
const structures_1 = require("@blackglory/structures");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class LRUCache {
|
7
|
-
constructor(limit) {
|
8
|
-
this.map = new structures_1.LRUMap(limit);
|
9
|
-
}
|
10
|
-
set(key, value) {
|
11
|
-
this.map.set(key, value);
|
12
|
-
}
|
13
|
-
get(key) {
|
14
|
-
if (this.map.has(key)) {
|
15
|
-
return [extra_memoize_1.State.Hit, this.map.get(key)];
|
16
|
-
}
|
17
|
-
else {
|
18
|
-
return [extra_memoize_1.State.Miss];
|
19
|
-
}
|
20
|
-
}
|
21
|
-
clear() {
|
22
|
-
this.map.clear();
|
23
|
-
}
|
24
|
-
}
|
25
|
-
exports.LRUCache = LRUCache;
|
26
|
-
//# sourceMappingURL=lru-cache.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../../../src/caches/lru-cache.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAC/C,iDAA6C;AAE7C,MAAa,QAAQ;IAGnB,YAAY,KAAa;QACvB,IAAI,CAAC,GAAG,GAAG,IAAI,mBAAM,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAA;SACvC;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF;AAtBD,4BAsBC"}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TLRUCacheWithStaleIfError = void 0;
|
4
|
-
const tlru_cache_1 = require("./tlru-cache");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class TLRUCacheWithStaleIfError {
|
7
|
-
constructor(limit, timeToLive, staleIfError) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.staleIfError = staleIfError;
|
10
|
-
this.cache = new tlru_cache_1.TLRUCache(limit, timeToLive + staleIfError);
|
11
|
-
}
|
12
|
-
set(key, value) {
|
13
|
-
this.cache.set(key, {
|
14
|
-
value,
|
15
|
-
updatedAt: Date.now()
|
16
|
-
});
|
17
|
-
}
|
18
|
-
get(key) {
|
19
|
-
const [state, record] = this.cache.get(key);
|
20
|
-
if (state === extra_memoize_1.State.Miss) {
|
21
|
-
return [extra_memoize_1.State.Miss];
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
const elapsed = Date.now() - record.updatedAt;
|
25
|
-
if (elapsed < this.timeToLive) {
|
26
|
-
return [extra_memoize_1.State.Hit, record.value];
|
27
|
-
}
|
28
|
-
else if (elapsed < this.timeToLive + this.staleIfError) {
|
29
|
-
return [extra_memoize_1.State.StaleIfError, record.value];
|
30
|
-
}
|
31
|
-
else {
|
32
|
-
return [extra_memoize_1.State.Miss];
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
exports.TLRUCacheWithStaleIfError = TLRUCacheWithStaleIfError;
|
38
|
-
//# sourceMappingURL=tlru-cache-with-stale-if-error.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"tlru-cache-with-stale-if-error.js","sourceRoot":"","sources":["../../../src/caches/tlru-cache-with-stale-if-error.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,iDAAyD;AAOzD,MAAa,yBAAyB;IAGpC,YACE,KAAa,EACL,UAAkB,EAClB,YAAoB;QADpB,eAAU,GAAV,UAAU,CAAQ;QAClB,iBAAY,GAAZ,YAAY,CAAQ;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAI,sBAAS,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAAC,CAAA;IAC9D,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,KAAK,KAAK,qBAAK,CAAC,IAAI,EAAE;YACxB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,CAAA;YAC7C,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE;gBAC7B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACxD,OAAO,CAAC,qBAAK,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAC1C;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;CACF;AAlCD,8DAkCC"}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TLRUCacheWithStaleWhileRevalidateAndStaleIfError = void 0;
|
4
|
-
const tlru_cache_1 = require("./tlru-cache");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class TLRUCacheWithStaleWhileRevalidateAndStaleIfError {
|
7
|
-
constructor(limit, timeToLive, staleWhileRevalidate, staleIfError) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.staleWhileRevalidate = staleWhileRevalidate;
|
10
|
-
this.staleIfError = staleIfError;
|
11
|
-
this.cache = new tlru_cache_1.TLRUCache(limit, timeToLive + staleWhileRevalidate + staleIfError);
|
12
|
-
}
|
13
|
-
set(key, value) {
|
14
|
-
this.cache.set(key, {
|
15
|
-
value,
|
16
|
-
updatedAt: Date.now()
|
17
|
-
});
|
18
|
-
}
|
19
|
-
get(key) {
|
20
|
-
const [state, record] = this.cache.get(key);
|
21
|
-
if (state === extra_memoize_1.State.Miss) {
|
22
|
-
return [extra_memoize_1.State.Miss];
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
const elapsed = Date.now() - record.updatedAt;
|
26
|
-
if (elapsed < this.timeToLive) {
|
27
|
-
return [extra_memoize_1.State.Hit, record.value];
|
28
|
-
}
|
29
|
-
else if (elapsed < this.timeToLive + this.staleWhileRevalidate) {
|
30
|
-
return [extra_memoize_1.State.StaleWhileRevalidate, record.value];
|
31
|
-
}
|
32
|
-
else if (elapsed < this.timeToLive + this.staleWhileRevalidate + this.staleIfError) {
|
33
|
-
return [extra_memoize_1.State.StaleIfError, record.value];
|
34
|
-
}
|
35
|
-
else {
|
36
|
-
return [extra_memoize_1.State.Miss];
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
}
|
41
|
-
exports.TLRUCacheWithStaleWhileRevalidateAndStaleIfError = TLRUCacheWithStaleWhileRevalidateAndStaleIfError;
|
42
|
-
//# sourceMappingURL=tlru-cache-with-stale-while-revalidate-and-stale-if-error.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"tlru-cache-with-stale-while-revalidate-and-stale-if-error.js","sourceRoot":"","sources":["../../../src/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,iDAAgF;AAOhF,MAAa,gDAAgD;IAG3D,YACE,KAAa,EACL,UAAkB,EAClB,oBAA4B,EAC5B,YAAoB;QAFpB,eAAU,GAAV,UAAU,CAAQ;QAClB,yBAAoB,GAApB,oBAAoB,CAAQ;QAC5B,iBAAY,GAAZ,YAAY,CAAQ;QAE5B,IAAI,CAAC,KAAK,GAAG,IAAI,sBAAS,CAAC,KAAK,EAAE,UAAU,GAAG,oBAAoB,GAAG,YAAY,CAAC,CAAA;IACrF,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QAOb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,KAAK,KAAK,qBAAK,CAAC,IAAI,EAAE;YACxB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,CAAA;YAC7C,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE;gBAC7B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,EAAE;gBAChE,OAAO,CAAC,qBAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAClD;iBAAM,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,YAAY,EAAE;gBACpF,OAAO,CAAC,qBAAK,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAC1C;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;CACF;AA3CD,4GA2CC"}
|
@@ -1,39 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TLRUCacheWithStaleWhileRevalidate = void 0;
|
4
|
-
const tlru_cache_1 = require("./tlru-cache");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class TLRUCacheWithStaleWhileRevalidate {
|
7
|
-
constructor(limit, timeToLive, staleWhileRevalidate) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.staleWhileRevalidate = staleWhileRevalidate;
|
10
|
-
this.cache = new tlru_cache_1.TLRUCache(limit, timeToLive + staleWhileRevalidate);
|
11
|
-
}
|
12
|
-
set(key, value) {
|
13
|
-
this.cache.set(key, {
|
14
|
-
value,
|
15
|
-
updatedAt: Date.now()
|
16
|
-
});
|
17
|
-
}
|
18
|
-
get(key) {
|
19
|
-
const [state, record] = this.cache.get(key);
|
20
|
-
if (state === extra_memoize_1.State.Miss) {
|
21
|
-
return [extra_memoize_1.State.Miss];
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
if (this.isStaleWhileRevalidate(record)) {
|
25
|
-
return [extra_memoize_1.State.StaleWhileRevalidate, record.value];
|
26
|
-
}
|
27
|
-
else {
|
28
|
-
return [extra_memoize_1.State.Hit, record.value];
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
isStaleWhileRevalidate(record) {
|
33
|
-
const timestamp = Date.now();
|
34
|
-
return record.updatedAt + this.timeToLive <= timestamp
|
35
|
-
&& record.updatedAt + this.timeToLive + this.staleWhileRevalidate > timestamp;
|
36
|
-
}
|
37
|
-
}
|
38
|
-
exports.TLRUCacheWithStaleWhileRevalidate = TLRUCacheWithStaleWhileRevalidate;
|
39
|
-
//# sourceMappingURL=tlru-cache-with-stale-while-revalidate.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"tlru-cache-with-stale-while-revalidate.js","sourceRoot":"","sources":["../../../src/caches/tlru-cache-with-stale-while-revalidate.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,iDAAiE;AAOjE,MAAa,iCAAiC;IAG5C,YACE,KAAa,EACL,UAAkB,EAClB,oBAA4B;QAD5B,eAAU,GAAV,UAAU,CAAQ;QAClB,yBAAoB,GAApB,oBAAoB,CAAQ;QAEpC,IAAI,CAAC,KAAK,GAAG,IAAI,sBAAS,CAAC,KAAK,EAAE,UAAU,GAAG,oBAAoB,CAAC,CAAA;IACtE,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,KAAK,KAAK,qBAAK,CAAC,IAAI,EAAE;YACxB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,IAAI,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE;gBACvC,OAAO,CAAC,qBAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAClD;iBAAM;gBACL,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;SACF;IACH,CAAC;IAED,sBAAsB,CAAC,MAAkB;QACvC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC5B,OAAO,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,IAAI,SAAS;eAC/C,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAA;IACnF,CAAC;CACF;AApCD,8EAoCC"}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TLRUCache = void 0;
|
4
|
-
const structures_1 = require("@blackglory/structures");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class TLRUCache {
|
7
|
-
constructor(limit, timeToLive) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.map = new structures_1.TLRUMap(limit);
|
10
|
-
}
|
11
|
-
set(key, value) {
|
12
|
-
this.map.set(key, value, this.timeToLive);
|
13
|
-
}
|
14
|
-
get(key) {
|
15
|
-
if (this.map.has(key)) {
|
16
|
-
return [extra_memoize_1.State.Hit, this.map.get(key)];
|
17
|
-
}
|
18
|
-
else {
|
19
|
-
return [extra_memoize_1.State.Miss];
|
20
|
-
}
|
21
|
-
}
|
22
|
-
clear() {
|
23
|
-
this.map.clear();
|
24
|
-
}
|
25
|
-
}
|
26
|
-
exports.TLRUCache = TLRUCache;
|
27
|
-
//# sourceMappingURL=tlru-cache.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"tlru-cache.js","sourceRoot":"","sources":["../../../src/caches/tlru-cache.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAChD,iDAA6C;AAE7C,MAAa,SAAS;IAGpB,YAAY,KAAa,EAAU,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;QACnD,IAAI,CAAC,GAAG,GAAG,IAAI,oBAAO,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IAC3C,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAA;SACvC;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF;AAtBD,8BAsBC"}
|
package/lib/es2015/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './caches/index';
|
package/lib/es2015/index.js
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./caches/index"), exports);
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/lib/es2015/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Cache = void 0;
|
4
|
-
const extra_memoize_1 = require("extra-memoize");
|
5
|
-
class Cache {
|
6
|
-
constructor() {
|
7
|
-
this.map = new Map();
|
8
|
-
}
|
9
|
-
set(key, value) {
|
10
|
-
this.map.set(key, value);
|
11
|
-
}
|
12
|
-
get(key) {
|
13
|
-
if (this.map.has(key)) {
|
14
|
-
return [extra_memoize_1.State.Hit, this.map.get(key)];
|
15
|
-
}
|
16
|
-
else {
|
17
|
-
return [extra_memoize_1.State.Miss];
|
18
|
-
}
|
19
|
-
}
|
20
|
-
delete(key) {
|
21
|
-
this.map.delete(key);
|
22
|
-
}
|
23
|
-
clear() {
|
24
|
-
this.map.clear();
|
25
|
-
}
|
26
|
-
}
|
27
|
-
exports.Cache = Cache;
|
28
|
-
//# sourceMappingURL=cache.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/caches/cache.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,KAAK;IAAlB;QACU,QAAG,GAAG,IAAI,GAAG,EAAE,CAAA;IAqBzB,CAAC;IAnBC,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACrB,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;SACtC;aAAM;YACL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;IACH,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF;AAtBD,sBAsBC"}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import { IStaleIfErrorCache, State } from 'extra-memoize';
|
2
|
-
export declare class ExpirableCacheWithStaleIfError<T> implements IStaleIfErrorCache<T> {
|
3
|
-
private timeToLive;
|
4
|
-
private staleIfError;
|
5
|
-
private cache;
|
6
|
-
constructor(timeToLive: number, staleIfError: number);
|
7
|
-
set(key: string, value: T): void;
|
8
|
-
get(key: string): [State.Miss] | [State.Hit | State.StaleIfError, T];
|
9
|
-
}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ExpirableCacheWithStaleIfError = void 0;
|
4
|
-
const expirable_cache_1 = require("./expirable-cache");
|
5
|
-
const extra_memoize_1 = require("extra-memoize");
|
6
|
-
class ExpirableCacheWithStaleIfError {
|
7
|
-
constructor(timeToLive, staleIfError) {
|
8
|
-
this.timeToLive = timeToLive;
|
9
|
-
this.staleIfError = staleIfError;
|
10
|
-
this.cache = new expirable_cache_1.ExpirableCache(timeToLive + staleIfError);
|
11
|
-
}
|
12
|
-
set(key, value) {
|
13
|
-
this.cache.set(key, {
|
14
|
-
value,
|
15
|
-
updatedAt: Date.now()
|
16
|
-
});
|
17
|
-
}
|
18
|
-
get(key) {
|
19
|
-
const [state, record] = this.cache.get(key);
|
20
|
-
if (state === extra_memoize_1.State.Miss) {
|
21
|
-
return [extra_memoize_1.State.Miss];
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
const elapsed = Date.now() - record.updatedAt;
|
25
|
-
if (elapsed < this.timeToLive) {
|
26
|
-
return [extra_memoize_1.State.Hit, record.value];
|
27
|
-
}
|
28
|
-
else if (elapsed < this.timeToLive + this.staleIfError) {
|
29
|
-
return [extra_memoize_1.State.StaleIfError, record.value];
|
30
|
-
}
|
31
|
-
else {
|
32
|
-
return [extra_memoize_1.State.Miss];
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
exports.ExpirableCacheWithStaleIfError = ExpirableCacheWithStaleIfError;
|
38
|
-
//# sourceMappingURL=expirable-cache-with-stale-if-error.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"expirable-cache-with-stale-if-error.js","sourceRoot":"","sources":["../../../src/caches/expirable-cache-with-stale-if-error.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAClD,iDAAyD;AAOzD,MAAa,8BAA8B;IAGzC,YAAoB,UAAkB,EAAU,YAAoB;QAAhD,eAAU,GAAV,UAAU,CAAQ;QAAU,iBAAY,GAAZ,YAAY,CAAQ;QAClE,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAc,CAAC,UAAU,GAAG,YAAY,CAAC,CAAA;IAC5D,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAQ;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAClB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,KAAK,KAAK,qBAAK,CAAC,IAAI,EAAE;YACxB,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,CAAA;YAC7C,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE;gBAC7B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACxD,OAAO,CAAC,qBAAK,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAC1C;iBAAM;gBAEL,OAAO,CAAC,qBAAK,CAAC,IAAI,CAAC,CAAA;aACpB;SACF;IACH,CAAC;CACF;AA9BD,wEA8BC"}
|
package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.d.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import { IStaleWhileRevalidateAndStaleIfErrorCache, State } from 'extra-memoize';
|
2
|
-
export declare class ExpirableCacheWithStaleWhileRevalidateAndStaleIfError<T> implements IStaleWhileRevalidateAndStaleIfErrorCache<T> {
|
3
|
-
private timeToLive;
|
4
|
-
private staleWhileRevalidate;
|
5
|
-
private staleIfError;
|
6
|
-
private cache;
|
7
|
-
constructor(timeToLive: number, staleWhileRevalidate: number, staleIfError: number);
|
8
|
-
set(key: string, value: T): void;
|
9
|
-
get(key: string): [State.Miss] | [
|
10
|
-
State.Hit | State.StaleWhileRevalidate | State.StaleIfError,
|
11
|
-
T
|
12
|
-
];
|
13
|
-
}
|