Add caching layer to WI save/load

This commit is contained in:
Cohee
2023-06-24 23:57:44 +03:00
parent 747f7829fd
commit 09eea3c8cd

View File

@@ -45,6 +45,8 @@ const world_info_position = {
};
const worldInfoCache = {};
async function getWorldInfoPrompt(chat2, maxContext) {
let worldInfoString = "", worldInfoBefore = "", worldInfoAfter = "";
@@ -124,6 +126,10 @@ async function loadWorldInfoData(name) {
return;
}
if (worldInfoCache[name]) {
return worldInfoCache[name];
}
const response = await fetch("/getworldinfo", {
method: "POST",
headers: getRequestHeaders(),
@@ -133,6 +139,7 @@ async function loadWorldInfoData(name) {
if (response.ok) {
const data = await response.json();
worldInfoCache[name] = data;
return data;
}
@@ -557,6 +564,8 @@ async function saveWorldInfo(name, data, immediately) {
return;
}
delete worldInfoCache[name];
if (immediately) {
return await _save(name, data);
}