[Bug] geminiCaches (/v1beta/cachedContents) has no entry/byte cap, TTL upper bound, or background eviction, allowing unbounded RAM growth
发生了什么 / What happened
Summary
In internal/api/gemini_caches.go:37-115, geminiCaches stores full aistudio.GenerateRequest payloads (including large conversation histories and inline media blobs) in items map[string]*geminiCache:
- No max entry count or max total byte limit.
- No upper TTL /
expireTimecap:expiration()(lines 59-78) accepts arbitrary future timestamps (e.g., year2099orttl: "87600h"). - No background cleanup:
removeExpiredLockedonly runs insideadd()andlist(), so expired caches remain in RAM indefinitely when no new caches are created.
Impact
Repeated POST /v1beta/cachedContents calls (or long TTLs with large contexts/media) grow Go heap memory unboundedly until OOM.
Suggested Fix
Enforce bounded capacity (max entries and/or max total bytes with LRU eviction), cap maximum TTL (e.g., 24h), and periodically evict expired entries.
版本 / Version
v0.3.14
每人最多同时打开 3 个 Issue,这个 Issue 已自动关闭。请等已有的 Issue 处理完再提,或把内容补充到已有的 Issue 里。
Each user can have at most 3 open issues at a time, so this one was closed automatically. Please wait until your existing issues are resolved, or add this to one of them.