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