@convo-lang/convo-lang
Version:
The language of AI
24 lines • 940 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConvoLocalStorageCache = void 0;
const ConvoHashCacheBase_1 = require("./ConvoHashCacheBase");
const convo_lib_1 = require("./convo-lib");
/**
* Caches conversation responses in memory
*/
class ConvoLocalStorageCache extends ConvoHashCacheBase_1.ConvoHashCacheBase {
keyPrefix;
constructor({ keyPrefix = 'ConvoLocalStorageCache::' } = {}) {
super(convo_lib_1.commonConvoCacheTypes.localStorage);
this.keyPrefix = keyPrefix;
}
getMessagesByKey(key) {
const v = globalThis.localStorage?.getItem(this.keyPrefix + key);
return v ? JSON.parse(v) : undefined;
}
cacheMessagesByKey(key, messages) {
globalThis.localStorage?.setItem(this.keyPrefix + key, JSON.stringify(messages));
}
}
exports.ConvoLocalStorageCache = ConvoLocalStorageCache;
//# sourceMappingURL=ConvoLocalStorageCache.js.map