@extra-memoize/memory-cache 0.2.10 → 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.
Files changed (107) hide show
  1. package/lib/caches/cache.js +24 -0
  2. package/lib/caches/cache.js.map +1 -0
  3. package/lib/caches/expirable-cache-with-stale-if-error.js +35 -0
  4. package/lib/caches/expirable-cache-with-stale-if-error.js.map +1 -0
  5. package/lib/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js +39 -0
  6. package/lib/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map +1 -0
  7. package/lib/caches/expirable-cache-with-stale-while-revalidate.js +35 -0
  8. package/lib/caches/expirable-cache-with-stale-while-revalidate.js.map +1 -0
  9. package/lib/caches/expirable-cache.js +23 -0
  10. package/lib/caches/expirable-cache.js.map +1 -0
  11. package/lib/caches/index.d.ts +10 -0
  12. package/lib/caches/index.js +11 -0
  13. package/lib/caches/index.js.map +1 -0
  14. package/lib/caches/lru-cache.js +22 -0
  15. package/lib/caches/lru-cache.js.map +1 -0
  16. package/lib/caches/tlru-cache-with-stale-if-error.js +35 -0
  17. package/lib/caches/tlru-cache-with-stale-if-error.js.map +1 -0
  18. package/lib/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js +39 -0
  19. package/lib/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js.map +1 -0
  20. package/lib/caches/tlru-cache-with-stale-while-revalidate.js +35 -0
  21. package/lib/caches/tlru-cache-with-stale-while-revalidate.js.map +1 -0
  22. package/lib/caches/tlru-cache.js +23 -0
  23. package/lib/caches/tlru-cache.js.map +1 -0
  24. package/lib/index.d.ts +1 -0
  25. package/lib/index.js +2 -0
  26. package/lib/index.js.map +1 -0
  27. package/package.json +33 -35
  28. package/src/caches/expirable-cache-with-stale-if-error.ts +4 -4
  29. package/src/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.ts +5 -5
  30. package/src/caches/expirable-cache-with-stale-while-revalidate.ts +4 -3
  31. package/src/caches/index.ts +10 -10
  32. package/src/caches/tlru-cache-with-stale-if-error.ts +4 -4
  33. package/src/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.ts +5 -5
  34. package/src/caches/tlru-cache-with-stale-while-revalidate.ts +4 -3
  35. package/src/index.ts +1 -1
  36. package/lib/es2015/caches/cache.js +0 -28
  37. package/lib/es2015/caches/cache.js.map +0 -1
  38. package/lib/es2015/caches/expirable-cache-with-stale-if-error.js +0 -38
  39. package/lib/es2015/caches/expirable-cache-with-stale-if-error.js.map +0 -1
  40. package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
  41. package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
  42. package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate.js +0 -38
  43. package/lib/es2015/caches/expirable-cache-with-stale-while-revalidate.js.map +0 -1
  44. package/lib/es2015/caches/expirable-cache.js +0 -27
  45. package/lib/es2015/caches/expirable-cache.js.map +0 -1
  46. package/lib/es2015/caches/index.d.ts +0 -10
  47. package/lib/es2015/caches/index.js +0 -27
  48. package/lib/es2015/caches/index.js.map +0 -1
  49. package/lib/es2015/caches/lru-cache.js +0 -26
  50. package/lib/es2015/caches/lru-cache.js.map +0 -1
  51. package/lib/es2015/caches/tlru-cache-with-stale-if-error.js +0 -38
  52. package/lib/es2015/caches/tlru-cache-with-stale-if-error.js.map +0 -1
  53. package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
  54. package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
  55. package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate.js +0 -38
  56. package/lib/es2015/caches/tlru-cache-with-stale-while-revalidate.js.map +0 -1
  57. package/lib/es2015/caches/tlru-cache.js +0 -27
  58. package/lib/es2015/caches/tlru-cache.js.map +0 -1
  59. package/lib/es2015/index.d.ts +0 -1
  60. package/lib/es2015/index.js +0 -18
  61. package/lib/es2015/index.js.map +0 -1
  62. package/lib/es2018/caches/cache.d.ts +0 -8
  63. package/lib/es2018/caches/cache.js +0 -28
  64. package/lib/es2018/caches/cache.js.map +0 -1
  65. package/lib/es2018/caches/expirable-cache-with-stale-if-error.d.ts +0 -9
  66. package/lib/es2018/caches/expirable-cache-with-stale-if-error.js +0 -38
  67. package/lib/es2018/caches/expirable-cache-with-stale-if-error.js.map +0 -1
  68. package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -13
  69. package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
  70. package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
  71. package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate.d.ts +0 -10
  72. package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate.js +0 -38
  73. package/lib/es2018/caches/expirable-cache-with-stale-while-revalidate.js.map +0 -1
  74. package/lib/es2018/caches/expirable-cache.d.ts +0 -9
  75. package/lib/es2018/caches/expirable-cache.js +0 -27
  76. package/lib/es2018/caches/expirable-cache.js.map +0 -1
  77. package/lib/es2018/caches/index.d.ts +0 -10
  78. package/lib/es2018/caches/index.js +0 -27
  79. package/lib/es2018/caches/index.js.map +0 -1
  80. package/lib/es2018/caches/lru-cache.d.ts +0 -8
  81. package/lib/es2018/caches/lru-cache.js +0 -26
  82. package/lib/es2018/caches/lru-cache.js.map +0 -1
  83. package/lib/es2018/caches/tlru-cache-with-stale-if-error.d.ts +0 -9
  84. package/lib/es2018/caches/tlru-cache-with-stale-if-error.js +0 -38
  85. package/lib/es2018/caches/tlru-cache-with-stale-if-error.js.map +0 -1
  86. package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -13
  87. package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js +0 -42
  88. package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate-and-stale-if-error.js.map +0 -1
  89. package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate.d.ts +0 -15
  90. package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate.js +0 -38
  91. package/lib/es2018/caches/tlru-cache-with-stale-while-revalidate.js.map +0 -1
  92. package/lib/es2018/caches/tlru-cache.d.ts +0 -9
  93. package/lib/es2018/caches/tlru-cache.js +0 -27
  94. package/lib/es2018/caches/tlru-cache.js.map +0 -1
  95. package/lib/es2018/index.d.ts +0 -1
  96. package/lib/es2018/index.js +0 -18
  97. package/lib/es2018/index.js.map +0 -1
  98. /package/lib/{es2015/caches → caches}/cache.d.ts +0 -0
  99. /package/lib/{es2015/caches → caches}/expirable-cache-with-stale-if-error.d.ts +0 -0
  100. /package/lib/{es2015/caches → caches}/expirable-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -0
  101. /package/lib/{es2015/caches → caches}/expirable-cache-with-stale-while-revalidate.d.ts +0 -0
  102. /package/lib/{es2015/caches → caches}/expirable-cache.d.ts +0 -0
  103. /package/lib/{es2015/caches → caches}/lru-cache.d.ts +0 -0
  104. /package/lib/{es2015/caches → caches}/tlru-cache-with-stale-if-error.d.ts +0 -0
  105. /package/lib/{es2015/caches → caches}/tlru-cache-with-stale-while-revalidate-and-stale-if-error.d.ts +0 -0
  106. /package/lib/{es2015/caches → caches}/tlru-cache-with-stale-while-revalidate.d.ts +0 -0
  107. /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 elapsed = Date.now() - record.updatedAt
40
- if (elapsed <= this.timeToLive) {
39
+ const timestamp = Date.now()
40
+ if (record.updatedAt + this.timeToLive > timestamp) {
41
41
  return [State.Hit, record.value]
42
- } else if (elapsed <= this.timeToLive + this.staleWhileRevalidate) {
42
+ } else if (record.updatedAt + this.timeToLive + this.staleWhileRevalidate > timestamp) {
43
43
  return [State.StaleWhileRevalidate, record.value]
44
- } else if (elapsed <= this.timeToLive + this.staleWhileRevalidate + this.staleIfError) {
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
@@ -1,4 +1,4 @@
1
- import { TLRUCache } from './tlru-cache'
1
+ import { TLRUCache } from './tlru-cache.js'
2
2
  import { IStaleWhileRevalidateCache, State } from 'extra-memoize'
3
3
 
4
4
  interface IRecord<T> {
@@ -38,7 +38,8 @@ export class TLRUCacheWithStaleWhileRevalidate<T> implements IStaleWhileRevalida
38
38
  }
39
39
 
40
40
  isStaleWhileRevalidate(record: IRecord<T>): boolean {
41
- return Date.now() - record.updatedAt > this.timeToLive
42
- && Date.now() - record.updatedAt <= this.timeToLive + this.staleWhileRevalidate
41
+ const timestamp = Date.now()
42
+ return record.updatedAt + this.timeToLive <= timestamp
43
+ && record.updatedAt + this.timeToLive + this.staleWhileRevalidate > timestamp
43
44
  }
44
45
  }
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,IAAI,IAAI,CAAC,UAAU,EAAE;gBAC9B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACzD,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
@@ -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,IAAI,IAAI,CAAC,UAAU,EAAE;gBAC9B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,EAAE;gBACjE,OAAO,CAAC,qBAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAClD;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,YAAY,EAAE;gBACrF,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,38 +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
- return Date.now() - record.updatedAt > this.timeToLive
34
- && Date.now() - record.updatedAt <= this.timeToLive + this.staleWhileRevalidate;
35
- }
36
- }
37
- exports.ExpirableCacheWithStaleWhileRevalidate = ExpirableCacheWithStaleWhileRevalidate;
38
- //# 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,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU;eAC/C,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAA;IACrF,CAAC;CACF;AA/BD,wFA+BC"}
@@ -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,IAAI,IAAI,CAAC,UAAU,EAAE;gBAC9B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACzD,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,IAAI,IAAI,CAAC,UAAU,EAAE;gBAC9B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,EAAE;gBACjE,OAAO,CAAC,qBAAK,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aAClD;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,YAAY,EAAE;gBACrF,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,38 +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
- return Date.now() - record.updatedAt > this.timeToLive
34
- && Date.now() - record.updatedAt <= this.timeToLive + this.staleWhileRevalidate;
35
- }
36
- }
37
- exports.TLRUCacheWithStaleWhileRevalidate = TLRUCacheWithStaleWhileRevalidate;
38
- //# 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,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU;eAC/C,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAA;IACrF,CAAC;CACF;AAnCD,8EAmCC"}
@@ -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"}
@@ -1 +0,0 @@
1
- export * from './caches/index';
@@ -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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
@@ -1,8 +0,0 @@
1
- import { ICache, State } from 'extra-memoize';
2
- export declare class Cache<T> implements ICache<T> {
3
- private map;
4
- set(key: string, value: T): void;
5
- get(key: string): [State.Miss] | [State.Hit, T];
6
- delete(key: string): void;
7
- clear(): void;
8
- }
@@ -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,IAAI,IAAI,CAAC,UAAU,EAAE;gBAC9B,OAAO,CAAC,qBAAK,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAA;aACjC;iBAAM,IAAI,OAAO,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE;gBACzD,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,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
- }