Streamlit st.cache_data and Docker health‑check integration: does caching persist across container stop/start?
0 reputation · 03 Sept 2024, 05:22 UTC
Goal: Verify whether the in‑memory cache created by st.cache_data remains available after a Docker container running a Streamlit app is stopped and later restarted by a health‑check that triggers on inactivity.
Constraint: Streamlit’s st.cache_data stores data in the Python process memory; when the container is stopped the process terminates, which normally destroys the cache. The official documentation does not specify any automatic persistence mechanism for this cache across container lifecycles, leaving the behavior undefined for low‑traffic deployments that rely on periodic container shutdown to save compute.
Question: Does st.cache_data survive a container stop/start cycle initiated by a Docker health‑check? If it does not, what is the recommended pattern to preserve cached data between restarts for a low‑traffic workload? Is there a supported way to offload the cache to a volume or external store without rewriting the caching logic?