1
import { IActiveCache } from './Interface'
4
* This pool is to keep track of in-memory cache used for LLM and Embeddings
6
export class CachePool {
7
activeLLMCache: IActiveCache = {}
8
activeEmbeddingCache: IActiveCache = {}
11
* Add to the llm cache pool
12
* @param {string} chatflowid
13
* @param {Map<any, any>} value
15
addLLMCache(chatflowid: string, value: Map<any, any>) {
16
this.activeLLMCache[chatflowid] = value
20
* Add to the embedding cache pool
21
* @param {string} chatflowid
22
* @param {Map<any, any>} value
24
addEmbeddingCache(chatflowid: string, value: Map<any, any>) {
25
this.activeEmbeddingCache[chatflowid] = value
29
* Get item from llm cache pool
30
* @param {string} chatflowid
32
getLLMCache(chatflowid: string): Map<any, any> | undefined {
33
return this.activeLLMCache[chatflowid]
37
* Get item from embedding cache pool
38
* @param {string} chatflowid
40
getEmbeddingCache(chatflowid: string): Map<any, any> | undefined {
41
return this.activeEmbeddingCache[chatflowid]
45
let cachePoolInstance: CachePool | undefined
47
export function getInstance(): CachePool {
48
if (cachePoolInstance === undefined) {
49
cachePoolInstance = new CachePool()
52
return cachePoolInstance