JIT Cache is a process/thread safe key-value cache
Branch: master
Clone or download
Latest commit 41eccda Feb 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
examples
examples_dash Improved key generation wrt args and kwarg functions Feb 10, 2019
tests Major change: from kv-store to function caching Feb 10, 2019
.gitignore Renamed module to package name Feb 8, 2019
.travis.yml Updated travis config for py3.7 Feb 9, 2019
BUILD.md Updated travis config for py3.7 Feb 9, 2019
LICENSE
README.md Updated README Feb 10, 2019
build_requirements.txt Improved documentation and build system Feb 9, 2019
create_local_env.sh Improved documentation and build system Feb 9, 2019
jitcache.py Removed print statement Feb 11, 2019
pre_push.sh
pyproject.toml Changed to black for formatting Feb 9, 2019
setup.cfg Testing CI Feb 9, 2019
setup.py Removed print statement Feb 11, 2019

README.md

Build Status Documentation Status Downloads

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)