AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] geminiCaches (/v1beta/cachedContents) has no entry/byte cap, TTL upper bound, or background eviction, allowing unbounded RAM growth

Open photobrand opened this issue 1 week ago • 1 comments

发生了什么 / 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 / expireTime cap: expiration() (lines 59-78) accepts arbitrary future timestamps (e.g., year 2099 or ttl: "87600h").
  • No background cleanup: removeExpiredLocked only runs inside add() and list(), 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

photobrand avatar Nov 22 '26 15:11 photobrand

每人最多同时打开 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.

github-actions[bot] avatar Nov 22 '26 15:11 github-actions[bot]