Question about st.cache_data TTL and Memory Cleanup
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 文档
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- python
调研方向
首先查看 issue 中引用的 Streamlit cache_data TTL 和 cache management 文档,然后追踪文档所述的过期条目行为和内存清理。确认文档是否解释了后台过期、保留的 Python 内存以及按条目回收;完成的标准是添加清晰且有依据的说明,或确定适当的文档缺口。
由索引模型根据 Issue 内容生成。
描述
Hi Streamlit Team,
I have a question about how st.cache_data works with ttl, specifically around memory cleanup.
For example:
@st.cache_data(ttl=3600)
def load_data():
...
Scenario
At 10:00 AM, User 1 calls the function.
The function caches a DataFrame of about 1 GB.
The cache TTL is 1 hour.
No one calls this function again until 4:00 PM.
What I observed
While monitoring my application’s memory usage, I noticed that even though the TTL had expired several hours earlier, the process memory did not decrease. For example, after the cached DataFrame increased the application’s memory to around 1 GB, the memory usage stayed close to 1 GB instead of dropping after the TTL expired.
This made me wonder:
Is this the expected behavior?
Does Streamlit have any background process that automatically removes expired cache entries from memory, or are expired entries only cleaned up when the cached function is called again?
If a cache entry has expired, is it removed from Streamlit’s cache while the underlying Python memory is still retained? If so, is there a recommended way to release or reclaim that memory?
I looked into the available cache management options, including:
max_entries
st.cache_data.clear()
function_name.clear()
However, none of these seem ideal for my use case.
Using max_entries across many cached functions would increase cache evictions, leading to more cache misses and recomputation, which impacts page performance.
Similarly, st.cache_data.clear() or function_name.clear() removes all cached entries (globally or for a function), which isn’t practical in a production application where other users may still be relying on those cached results.
Is there a recommended approach for releasing memory used by expired cache entries without clearing the entire cache or aggressively limiting the cache size?
I also tested the behavior with a second user.
At 4:00 PM, User 2 called the same cached function with different input parameters.
The function created a new cached result of approximately 800 MB.
I expected the old cache entry to be released and the application’s memory usage to settle around 800 MB. Instead, the process memory increased from about 1 GB to approximately 1.8 GB, which suggests that the earlier cached data was still occupying memory while the new cache entry was added.
Is this also the expected behavior? If so, when is the memory used by an expired cache entry actually released?
I’d appreciate any clarification on how TTL expiration and memory management are intended to work internally.
Thank you!
- 主要语言
- JavaScript
- 星标
- 178
- 派生
- 711
- 平均合并
- 1 天 21 小时
- 30 天内合并 PR
- 19
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
streamlit/docs 的其他 Issue
-
docs needs triage
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 2 天内回复
-
Fix description of Azure SQL support可能已有人在做 @Nikhil-jaiswal007 于 185 天前认领。 未关闭docs needs triage
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 2 天内回复
-
docs
难度 2/5 1-3 小时 新手友好度 62/100
streamlit/docs#719 · 2 条评论 · 1 个 reaction ·
维护者通常 2 天内回复
-
App.run() does not serve a mounted ASGI app (routes=[Mount(...)]) that works with uvicorn.run(app)未关闭bug needs triage
难度 4/5 1-2 天 新手友好度 22/100
维护者通常 2 天内回复
-
bug needs triage
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 2 天内回复
相似的 Issue
-
fix(套件): test_bundle 往仓库的 preset/skills 写哨兵,并发跑的 test_installer 拷贝时撞 ENOENT(CI 红)可能已有人在做 @Miaotofu01 今天认领。 未关闭needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
Miaotofu01/Study-Mate#216 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
-
beginner-friendly category:fixtures community enhancement first-timers-only good first issue hacktoberfest help wanted low hanging fruit micro-contribution type: task up-for-grabs
难度 1/5 1 小时以内 新手友好度 85/100
Berserk-hub150/skillhawk#229 · 1 条评论 ·
维护者通常 8 天内回复
-
WlanConfUpdateSensor falsely reports wifi interface appearing when sysfs inode cache is reclaimed未关闭
难度 2/5 1-3 小时 新手友好度 82/100
firewalla/firerouter#2180 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
andromarces/agent-loops#976 ·
维护者通常 1 天内回复