@woosh/meep-engine 2.84.10 → 2.84.11

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.
@@ -60814,7 +60814,7 @@ class Cache {
60814
60814
 
60815
60815
  if (
60816
60816
  this.weight > this.maxWeight
60817
- && new_weight >= this.maxWeight //make it less likely to drop entire cache
60817
+ && new_weight <= this.maxWeight //make it less likely to drop entire cache
60818
60818
  ) {
60819
60819
  this.evictUntilWeight(this.maxWeight);
60820
60820
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.84.10",
8
+ "version": "2.84.11",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -216,7 +216,7 @@ export class Cache {
216
216
 
217
217
  if (
218
218
  this.weight > this.maxWeight
219
- && new_weight >= this.maxWeight //make it less likely to drop entire cache
219
+ && new_weight <= this.maxWeight //make it less likely to drop entire cache
220
220
  ) {
221
221
  this.evictUntilWeight(this.maxWeight);
222
222
  }
@@ -41,7 +41,7 @@ function record_get_value_weight(record) {
41
41
  /**
42
42
  * Asynchronous cache capable of resolving its own values by keys
43
43
  * Modelled on Guava's LoadingCache concept
44
- * @template K,V
44
+ * @template K, V
45
45
  */
46
46
  export class LoadingCache {
47
47
  /**
@@ -73,7 +73,6 @@ export class LoadingCache {
73
73
 
74
74
  /**
75
75
  * @see {@link Cache} for more details on what each parameter means
76
- * @template K,V
77
76
  * @param [maxWeight]
78
77
  * @param [keyWeigher]
79
78
  * @param [valueWeigher]
@@ -183,6 +182,15 @@ export class LoadingCache {
183
182
  this.#internal.put(key, new Record(Promise.resolve(value), current_time_in_seconds()));
184
183
  }
185
184
 
185
+ /**
186
+ *
187
+ * @param {K} key
188
+ * @returns {boolean}
189
+ */
190
+ contains(key) {
191
+ return this.#internal.contains(key);
192
+ }
193
+
186
194
  /**
187
195
  *
188
196
  * @param {K} key
@@ -84,3 +84,38 @@ test("clear", async () => {
84
84
 
85
85
  expect(await cache.get("x")).toEqual(3);
86
86
  });
87
+
88
+ test("eviction", async () => {
89
+
90
+ /**
91
+ *
92
+ * @type {LoadingCache<number, number>}
93
+ */
94
+ const cache = new LoadingCache({
95
+ valueWeigher(num) {
96
+ return num;
97
+ },
98
+ load: async () => {
99
+ return 2;
100
+ },
101
+ maxWeight: 6,
102
+ });
103
+
104
+ await cache.get(1);
105
+ await cache.get(2);
106
+ await cache.get(3);
107
+
108
+ expect(cache.contains(1)).toBe(true);
109
+ expect(cache.contains(2)).toBe(true);
110
+ expect(cache.contains(3)).toBe(true);
111
+
112
+ await cache.get(4);
113
+
114
+ await delay(1);
115
+
116
+ expect(cache.contains(1)).toBe(false);
117
+ expect(cache.contains(2)).toBe(true);
118
+ expect(cache.contains(3)).toBe(true);
119
+ expect(cache.contains(4)).toBe(true);
120
+
121
+ });