jitcache是一个即时键值缓存,它是线程/进程安全的
jitcache的Python项目详细描述
jitcache
jitcache是线程/进程安全的即时键值缓存。jitcache还可以防止重复计算 当多个工作者请求相同的值时。
jitcache旨在通过缓存结果和减少cpu负载来提高plot.ly dash应用程序的性能。
安装
通过PIP安装:
$ pip install jitcache
文档
这里有完整的文档https://jitcache.readthedocs.io/
基本用法
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))
输出:
Slow Function Called
40
plot.ly破折号用法
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)