add cleanup function for user ccache and world cache

This commit is contained in:
pa
2025-10-31 19:00:09 +09:00
committed by Natsumi
parent 69923c2655
commit 0d3c1f646b
2 changed files with 62 additions and 0 deletions
+18
View File
@@ -215,6 +215,23 @@ export const useWorldStore = defineStore('World', () => {
}
}
function cleanupWorldCache(WorldCache) {
const maxCacheSize = 10000;
if (WorldCache.size <= maxCacheSize) {
return;
}
const deletedCount = WorldCache.size - maxCacheSize;
while (WorldCache.size > maxCacheSize) {
const deletedKey = WorldCache.keys().next().value;
WorldCache.delete(deletedKey);
}
console.log(
`World cache cleanup: Deleted ${deletedCount}. Current cache size: ${WorldCache.size}`
);
}
/**
*
* @param {object} json
@@ -270,6 +287,7 @@ export const useWorldStore = defineStore('World', () => {
//
...json
};
cleanupWorldCache(cachedWorlds);
cachedWorlds.set(ref.id, ref);
} else {
Object.assign(ref, json);