mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Proper caching for loaded WI
- Implement StructurecCloneMap, which is a map that provides structured clones on both get and set - Don't delete WI cache on save, but update the cache - Ensure that cache is updated immediately, so any future get will load the new saved data already - Still be consistent with clones, so requested cache data that wasn't saved isn't taken into account
This commit is contained in:
@@ -16,6 +16,7 @@ import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandE
|
||||
import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||
import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
|
||||
import { callGenericPopup, Popup, POPUP_TYPE } from './popup.js';
|
||||
import { StructuredCloneMap } from './util/StructuredCloneMap.js';
|
||||
|
||||
export {
|
||||
world_info,
|
||||
@@ -746,7 +747,8 @@ export const wi_anchor_position = {
|
||||
after: 1,
|
||||
};
|
||||
|
||||
const worldInfoCache = new Map();
|
||||
/** @type {StructuredCloneMap<string,object>} */
|
||||
const worldInfoCache = new StructuredCloneMap();
|
||||
|
||||
/**
|
||||
* Gets the world info based on chat messages.
|
||||
@@ -3280,7 +3282,8 @@ async function saveWorldInfo(name, data, immediately) {
|
||||
return;
|
||||
}
|
||||
|
||||
worldInfoCache.delete(name);
|
||||
// Update cache immediately, so any future call can pull from this
|
||||
worldInfoCache.set(name, structuredClone(data));
|
||||
|
||||
if (immediately) {
|
||||
return await _save(name, data);
|
||||
|
Reference in New Issue
Block a user