mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add caching layer to WI save/load
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user