@convo-lang/convo-lang
Version:
The language of AI
20 lines • 745 B
JavaScript
import { ConvoHashCacheBase } from "./ConvoHashCacheBase";
import { commonConvoCacheTypes } from "./convo-lib";
/**
* Caches conversation responses in memory
*/
export class ConvoLocalStorageCache extends ConvoHashCacheBase {
keyPrefix;
constructor({ keyPrefix = 'ConvoLocalStorageCache::' } = {}) {
super(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));
}
}
//# sourceMappingURL=ConvoLocalStorageCache.js.map