@adventurelabs/scout-core 1.0.78 → 1.0.79
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/dist/helpers/cache.js +16 -6
- package/package.json +1 -1
package/dist/helpers/cache.js
CHANGED
|
@@ -33,12 +33,18 @@ export class ScoutCache {
|
|
|
33
33
|
const db = event.target.result;
|
|
34
34
|
// Create herd modules store
|
|
35
35
|
if (!db.objectStoreNames.contains(HERD_MODULES_STORE)) {
|
|
36
|
-
const herdModulesStore = db.createObjectStore(HERD_MODULES_STORE, {
|
|
37
|
-
|
|
36
|
+
const herdModulesStore = db.createObjectStore(HERD_MODULES_STORE, {
|
|
37
|
+
keyPath: "herdId",
|
|
38
|
+
});
|
|
39
|
+
herdModulesStore.createIndex("timestamp", "timestamp", {
|
|
40
|
+
unique: false,
|
|
41
|
+
});
|
|
38
42
|
}
|
|
39
43
|
// Create cache metadata store
|
|
40
44
|
if (!db.objectStoreNames.contains(CACHE_METADATA_STORE)) {
|
|
41
|
-
const metadataStore = db.createObjectStore(CACHE_METADATA_STORE, {
|
|
45
|
+
const metadataStore = db.createObjectStore(CACHE_METADATA_STORE, {
|
|
46
|
+
keyPath: "key",
|
|
47
|
+
});
|
|
42
48
|
}
|
|
43
49
|
console.log("[ScoutCache] Database schema upgraded");
|
|
44
50
|
};
|
|
@@ -104,8 +110,9 @@ export class ScoutCache {
|
|
|
104
110
|
getAllRequest.onsuccess = () => {
|
|
105
111
|
const cacheEntries = getAllRequest.result;
|
|
106
112
|
const herdModules = cacheEntries
|
|
107
|
-
.
|
|
108
|
-
.
|
|
113
|
+
.filter((entry) => entry.data && entry.data.herd && entry.data.herd.slug)
|
|
114
|
+
.map((entry) => entry.data)
|
|
115
|
+
.sort((a, b) => (a.herd?.slug || "").localeCompare(b.herd?.slug || ""));
|
|
109
116
|
// Update stats
|
|
110
117
|
if (herdModules.length > 0) {
|
|
111
118
|
this.stats.hits++;
|
|
@@ -186,7 +193,10 @@ export class ScoutCache {
|
|
|
186
193
|
return { shouldRefresh: true, reason: "Cache is stale" };
|
|
187
194
|
}
|
|
188
195
|
if (maxAgeMs && result.age > maxAgeMs) {
|
|
189
|
-
return {
|
|
196
|
+
return {
|
|
197
|
+
shouldRefresh: true,
|
|
198
|
+
reason: `Cache age (${Math.round(result.age / 1000)}s) exceeds max age (${Math.round(maxAgeMs / 1000)}s)`,
|
|
199
|
+
};
|
|
190
200
|
}
|
|
191
201
|
return { shouldRefresh: false, reason: "Cache is valid and fresh" };
|
|
192
202
|
}
|