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) {
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user