Conversation
* develop: De-flake ScriptRunner_test.py (streamlit#1195)
* develop: Speed up `make jstest` on CircleCI
| max_entries, | ||
| ttl, | ||
| ) | ||
| mem_cache = TTLCache(maxsize=max_entries, ttl=ttl, timer=TTLCACHE_TIMER) |
There was a problem hiding this comment.
What are the other Timer types?
There was a problem hiding this comment.
Changing any of the cache params trashes all the previous cache entries? Is this communicated to the user somewhere?
There was a problem hiding this comment.
The timer types are just functions that return values. (So: time.time(), time.monotonic(), etc.) The only reason it's explicitly specified here is so that the passed-in timer can be patched in unit tests. I'll add a comment to that effect!
There was a problem hiding this comment.
Changing any of the cache params trashes all the previous cache entries? Is this communicated to the user somewhere?
Not explicitly, no. Though changing anything else about the function (its name, its contents) also trashes the cache, so this seems like a reasonable thing to do without spelling it out. I'm willing to change it if there's disagreement, though!
| # we must retrieve the cache object *and* perform the cached-value lookup | ||
| # inside the decorated function. | ||
|
|
||
| func_hasher = CodeHasher("md5", None, hash_funcs) |
There was a problem hiding this comment.
Why passing None instead of a hashlib.new("md5")?
There was a problem hiding this comment.
If you pass None, it just creates the hasher itself. It's a confusing API; I think Thiago may be changing it. (The reason not to pass None is if you want access to the hasher.)
| # functions in the same module will not share a hash. | ||
| func_hasher.update(func.__module__) | ||
| func_hasher.update(func.__qualname__) | ||
| func_hasher.update(func) |
There was a problem hiding this comment.
So now we hash the function twice? Once for the function cache key and once for the hash of the function call?
There was a problem hiding this comment.
Yes. I don't think there's a great way to solve this without some API surgery. The second hash happens in a separate hasher instance (by necessity).
* develop: file_uploader: support for multiple files (streamlit#1183) Another attempt at test_multiple_scriptrunners timeouts (streamlit#1211)
* develop: Better error messages for st.cache (streamlit#1146) Fix st.cache (streamlit#1208) file_uploader: support for multiple files (streamlit#1183) Another attempt at test_multiple_scriptrunners timeouts (streamlit#1211) Speed up `make jstest` on CircleCI De-flake ScriptRunner_test.py (streamlit#1195)
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
_MemCachesclass. Each cache is keyed off its wrapped function's fully qualified name, and its contents.There's a new
ScriptRunnertest that makes sure that caches are reused across multiple runs of the same script.