mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 09:00:52 +03:00
Feat/Implement caching for MCP toolkit in CachePool (#4897)
feat: Implement caching for MCP toolkit in CachePool - Added methods to CachePool for managing MCP toolkit cache. - Integrated caching logic in CustomMCP to store and retrieve toolkit data based on workspaceId and configuration. - Updated node service to pass cachePool to CustomMCP for enhanced performance.
This commit is contained in:
@@ -8,6 +8,7 @@ export class CachePool {
|
||||
private redisClient: Redis | null = null
|
||||
activeLLMCache: IActiveCache = {}
|
||||
activeEmbeddingCache: IActiveCache = {}
|
||||
activeMCPCache: { [key: string]: any } = {}
|
||||
|
||||
constructor() {
|
||||
if (process.env.MODE === MODE.QUEUE) {
|
||||
@@ -73,6 +74,29 @@ export class CachePool {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to the mcp toolkit cache pool
|
||||
* @param {string} cacheKey
|
||||
* @param {any} value
|
||||
*/
|
||||
async addMCPCache(cacheKey: string, value: any) {
|
||||
// Only add to cache for non-queue mode, because we are storing the toolkit instances in memory, and we can't store them in redis
|
||||
if (process.env.MODE !== MODE.QUEUE) {
|
||||
this.activeMCPCache[`mcpCache:${cacheKey}`] = value
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from mcp toolkit cache pool
|
||||
* @param {string} cacheKey
|
||||
*/
|
||||
async getMCPCache(cacheKey: string): Promise<any | undefined> {
|
||||
if (process.env.MODE !== MODE.QUEUE) {
|
||||
return this.activeMCPCache[`mcpCache:${cacheKey}`]
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from llm cache pool
|
||||
* @param {string} chatflowid
|
||||
|
||||
@@ -103,7 +103,8 @@ const getSingleNodeAsyncOptions = async (nodeName: string, requestBody: any): Pr
|
||||
componentNodes: appServer.nodesPool.componentNodes,
|
||||
previousNodes: requestBody.previousNodes,
|
||||
currentNode: requestBody.currentNode,
|
||||
searchOptions: requestBody.searchOptions
|
||||
searchOptions: requestBody.searchOptions,
|
||||
cachePool: appServer.cachePool
|
||||
})
|
||||
|
||||
return dbResponse
|
||||
|
||||
Reference in New Issue
Block a user