@static-suite/static-suite-data-server 0.0.4 → 0.0.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cacheBinManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/cache/cacheBinManager.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAE/C,oBAAY,KAAK,GAAG;IAClB;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;;;OAMG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAE5B;;;;OAIG;IACH,IAAI,IAAI,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAoBF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KA6BnB,CAAC"}
1
+ {"version":3,"file":"cacheBinManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/cache/cacheBinManager.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAE/C,oBAAY,KAAK,GAAG;IAClB;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;;;OAMG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAE5B;;;;OAIG;IACH,IAAI,IAAI,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAgCF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,EAAE,KA8BnB,CAAC"}
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cache = void 0;
4
+ /**
5
+ * Keeps a list of consumed bins to be able to clear them later.
6
+ *
7
+ * "data" is a Map and its bins can be removed, but those bins are
8
+ * Maps at the same time. That leads to having bin objects used by
9
+ * some module that cannot be cleared when Cache::clear() runs.
10
+ *
11
+ */
12
+ const consumedBins = new Map();
4
13
  const data = new Map();
5
14
  /**
6
15
  * Initializes a cache bin.
@@ -14,7 +23,9 @@ const data = new Map();
14
23
  *
15
24
  */
16
25
  const initBin = (binId) => {
17
- data.set(binId, new Map());
26
+ const bin = new Map();
27
+ data.set(binId, bin);
28
+ consumedBins.set(binId, bin);
18
29
  return data.get(binId);
19
30
  };
20
31
  /**
@@ -43,11 +54,12 @@ exports.cache = {
43
54
  */
44
55
  keys: () => Array.from(data.keys()),
45
56
  /**
46
- * Gets an array of keys of all available cache bins.
47
- *
48
- * @returns An array of cache bin keys.
57
+ * Deletes all available cache bins.
49
58
  */
50
59
  clear: () => {
60
+ consumedBins.forEach(bin => {
61
+ bin.clear();
62
+ });
51
63
  data.clear();
52
64
  },
53
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-suite/static-suite-data-server",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A flexible, fast and developer friendly Data Server for Static Suite",
5
5
  "main": "./dist/lib/index.js",
6
6
  "typings": "./dist/lib/index.d.ts",
@@ -31,6 +31,16 @@ export type Cache = {
31
31
  clear(): void;
32
32
  };
33
33
 
34
+ /**
35
+ * Keeps a list of consumed bins to be able to clear them later.
36
+ *
37
+ * "data" is a Map and its bins can be removed, but those bins are
38
+ * Maps at the same time. That leads to having bin objects used by
39
+ * some module that cannot be cleared when Cache::clear() runs.
40
+ *
41
+ */
42
+ const consumedBins = new Map<string, CacheBin<any>>();
43
+
34
44
  const data = new Map<string, CacheBin<any>>();
35
45
 
36
46
  /**
@@ -45,7 +55,9 @@ const data = new Map<string, CacheBin<any>>();
45
55
  *
46
56
  */
47
57
  const initBin = <Type>(binId: string): CacheBin<Type> => {
48
- data.set(binId, new Map<string, Type>());
58
+ const bin = new Map<string, Type>();
59
+ data.set(binId, bin);
60
+ consumedBins.set(binId, bin);
49
61
  return data.get(binId) as CacheBin<Type>;
50
62
  };
51
63
 
@@ -78,11 +90,12 @@ export const cache: Cache = {
78
90
  keys: () => Array.from(data.keys()),
79
91
 
80
92
  /**
81
- * Gets an array of keys of all available cache bins.
82
- *
83
- * @returns An array of cache bin keys.
93
+ * Deletes all available cache bins.
84
94
  */
85
95
  clear: () => {
96
+ consumedBins.forEach(bin => {
97
+ bin.clear();
98
+ });
86
99
  data.clear();
87
100
  },
88
101
  };