Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thread safety and TTL to pn.state.as_cached #3198

Merged
merged 3 commits into from
Feb 15, 2022
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Feb 15, 2022

Now that we have the ability to set --num-threads I expect many more users will leverage threads to speed up their application. However not all functionality in Panel was written with thread-safety in mind. This PR ensures that pn.state.as_cached maintains thread locks for each cache key ensuring that if multiple threads are trying to access the same cache key at the same time only one of the executes the function that is being cached on.

Additionally this PR also adds a TTL (time-to-live) for cache items allowing users to declare when a cached value expires and has to be refreshed.

@codecov
Copy link

codecov bot commented Feb 15, 2022

Codecov Report

Merging #3198 (98cb580) into master (4ae7887) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3198      +/-   ##
==========================================
+ Coverage   82.99%   83.01%   +0.02%     
==========================================
  Files         193      193              
  Lines       25626    25658      +32     
==========================================
+ Hits        21268    21300      +32     
  Misses       4358     4358              
Impacted Files Coverage Δ
panel/io/state.py 70.18% <100.00%> (+1.35%) ⬆️
panel/tests/conftest.py 94.89% <100.00%> (+0.03%) ⬆️
panel/tests/io/test_state.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ae7887...98cb580. Read the comment docs.

@MarcSkovMadsen
Copy link
Collaborator

Ttl is really important. Thanks

@philippjfr philippjfr merged commit 430f7fa into master Feb 15, 2022
@philippjfr philippjfr deleted the as_cached_enhance branch February 15, 2022 15:03
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.

2 participants