Skip to content

Commit 239fc12

Browse files
authored
feat: Use LRUCache instead of Map in MemoryCache (#774)
1 parent bc9120f commit 239fc12

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

packages/tools/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@ai-sdk/anthropic": "^2.0.25",
1515
"@ai-sdk/openai": "^2.0.23",
1616
"ai": "^5.0.29",
17+
"lru-cache": "^11.2.6",
1718
"openai": "^4.104.0",
1819
"supermemory": "^3.0.0-alpha.26",
1920
"zod": "^4.1.5"

packages/tools/src/shared/cache.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { LRUCache } from "lru-cache"
12
import type { MemoryMode } from "./types"
23

34
/**
45
* Generic memory cache for storing per-turn memories to avoid redundant API calls.
56
* Used to cache memory retrieval results during tool-call loops within the same turn.
67
*/
78
export class MemoryCache<T = string> {
8-
private cache: Map<string, T> = new Map()
9+
private cache: LRUCache<string, T> = new LRUCache({ max: 100 })
910

1011
/**
1112
* Generates a cache key for the current turn based on context parameters.

0 commit comments

Comments
 (0)