Question about st.cache_data TTL and Memory Cleanup
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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
- フォーク
- 708
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 12
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
streamlit/docs のほかの issue
-
docs needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 2 日以内に返信
-
Fix description of Azure SQL support対応中かも @Nikhil-jaiswal007 が 179 日前に担当しました。 オープンdocs needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
streamlit/docs#1260 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
docs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
streamlit/docs#719 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 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
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
[scanner] check:spelling skips blog/ — posts and author metadata are never spell-checked対応中かも @hivecommons-hive が今日担当しました。 オープンagent/scanner bug hive/covered-by-pr hive/hosted-available-lke648397-260827-5n31
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
cncf/endusers#1452 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Edit: HTVKey.vnオープンchannels:edit check:passed
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 6 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
MatAtBread/matbot#95 ·
メンテナーはふだん 1 日以内に返信
-
Status: Pending Review Type: Feature Request
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
OpenRefine/OpenRefine#8019 ·
メンテナーはふだん 1 日以内に返信