Flowise

Форк
0
/
CachePool.ts 
53 строки · 1.3 Кб
1
import { IActiveCache } from './Interface'
2

3
/**
4
 * This pool is to keep track of in-memory cache used for LLM and Embeddings
5
 */
6
export class CachePool {
7
    activeLLMCache: IActiveCache = {}
8
    activeEmbeddingCache: IActiveCache = {}
9

10
    /**
11
     * Add to the llm cache pool
12
     * @param {string} chatflowid
13
     * @param {Map<any, any>} value
14
     */
15
    addLLMCache(chatflowid: string, value: Map<any, any>) {
16
        this.activeLLMCache[chatflowid] = value
17
    }
18

19
    /**
20
     * Add to the embedding cache pool
21
     * @param {string} chatflowid
22
     * @param {Map<any, any>} value
23
     */
24
    addEmbeddingCache(chatflowid: string, value: Map<any, any>) {
25
        this.activeEmbeddingCache[chatflowid] = value
26
    }
27

28
    /**
29
     * Get item from llm cache pool
30
     * @param {string} chatflowid
31
     */
32
    getLLMCache(chatflowid: string): Map<any, any> | undefined {
33
        return this.activeLLMCache[chatflowid]
34
    }
35

36
    /**
37
     * Get item from embedding cache pool
38
     * @param {string} chatflowid
39
     */
40
    getEmbeddingCache(chatflowid: string): Map<any, any> | undefined {
41
        return this.activeEmbeddingCache[chatflowid]
42
    }
43
}
44

45
let cachePoolInstance: CachePool | undefined
46

47
export function getInstance(): CachePool {
48
    if (cachePoolInstance === undefined) {
49
        cachePoolInstance = new CachePool()
50
    }
51

52
    return cachePoolInstance
53
}
54

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.