jitcache is a just-in-time key-value cache that isthread/process safe
Project description
jitcache
jitcache is a just-in-time key-value cache that is thread/process safe. jitcache also prevents repeated computation when multiple workers request the same value.
jitcache was designed to improve the performance of Plot.ly Dash apps by caching results and reducing CPU load.
Installation
Install via pip:
$ pip install jitcache
Documentation
Full documentation available here https://jitcache.readthedocs.io/
Basic Usage
from jitcache import Cache
import time
cache = Cache()
@cache.memoize
def slow_fn(input_1, input_2, input_3=10):
print("Slow Function Called")
time.sleep(1)
return input_1 * input_2 * input_3
print(slow_fn(10, 2))
Output:
Slow Function Called
40
Plot.ly Dash Usage
import dash
import dash_html_components as html
from jitcache import Cache
import dash_core_components as dcc
cache = Cache()
app = dash.Dash(__name__)
server = app.server
app.layout = html.Div(
children=[
html.Div(id="output-container-dropdown1", children=[]),
html.Div(id="output-container-dropdown2", children=[]),
dcc.Dropdown(
options=[
{"label": "New York City", "value": "NYC"},
{"label": "Montréal", "value": "MTL"},
{"label": "San Francisco", "value": "SF"},
],
value="MTL",
id="dropdown",
),
]
)
@app.callback(
dash.dependencies.Output("output-container-dropdown1", "children"),
[dash.dependencies.Input("dropdown", "value")],
)
@cache.memoize
def update_output1(input_dropdown):
print("run1")
return input_dropdown
@app.callback(
dash.dependencies.Output("output-container-dropdown2", "children"),
[dash.dependencies.Input("dropdown", "value")],
)
@cache.memoize
def update_output2(input_dropdown):
print("run2")
return input_dropdown
if __name__ == "__main__":
app.run_server(debug=True)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jitcache-0.32-py3-none-any.whl.
File metadata
- Download URL: jitcache-0.32-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.0 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bd4e3913958e1b4690a1d73dd6e6d687fd134209da309956d45e5963b097228
|
|
| MD5 |
c53c4d5aa2a271e880596e36b79e6a91
|
|
| BLAKE2b-256 |
7b8aa48fb0d22dc3abd3a23acc19bfb3b64dcca8f61c9611be6fa1ea933f7d5c
|