Skip to content

st.cache expiration#1152

Merged
tconkling merged 10 commits intostreamlit:developfrom
tconkling:tim/STCacheExpiration
Mar 3, 2020
Merged

st.cache expiration#1152
tconkling merged 10 commits intostreamlit:developfrom
tconkling:tim/STCacheExpiration

Conversation

@tconkling
Copy link
Copy Markdown
Contributor

@tconkling tconkling commented Feb 27, 2020

Adds ttl and max_entries params to @st.cache

  • Each @st.cached function now has its own in-memory cache (previously, all functions shared a single cache).
  • cachetools.LRUCache and cachetools.TTLCache replace raw dictionaries as the cache implementations.

This closes #364. (Well, partly: per discussions with @tvst and @treuille, the other bits of that ticket (global and finalizer_func options) are going to wait for more discussion about caching changes.)

@tconkling tconkling requested a review from a team as a code owner February 27, 2020 00:27
* develop:
  Py2k Decimation: first pass, removing compatibility.py (streamlit#1127)
  Upgrading vega and vega-lite (streamlit#1156)
  Fixing progressbar animation when switching tabs (streamlit#1149)
  Raise our default max_upload_size to 200 MB (streamlit#1151)
  Fixing examples on mobile (streamlit#1145)
@tconkling tconkling merged commit 202cd80 into streamlit:develop Mar 3, 2020
@tconkling tconkling deleted the tim/STCacheExpiration branch March 3, 2020 15:51
sthagen added a commit to sthagen/streamlit-streamlit that referenced this pull request Mar 3, 2020
@tconkling tconkling mentioned this pull request Mar 10, 2020
tconkling added a commit that referenced this pull request Mar 10, 2020
This fixes breakage that I introduced in #1152 

Rather than creating the cache as a local variable in the st.cache wrapper, we instead manage all caches in a global `_MemCaches` class. Each cache is keyed off its wrapped function's fully qualified name, and its contents.

There's a new `ScriptRunner` test that makes sure that caches are reused across multiple runs of the same script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better control of cached object lifecycles

2 participants