Skip to main content

Simple user directory respecting JSON cache for expensive functions.

Project description

Provides a function decorator that caches the return value in a JSON file in the appropriate application cache directory.

It requires all function parameters and return values to be encodeable to JSON, so that the cache is human-readable.

It supports a “vary” guard value (e.g. a data model version) that protects against using old versions of cache.

https://travis-ci.org/JohannesEbke/app_json_file_cache.svg?branch=master

Usage

Example usage:

from app_json_file_cache import AppCache
cache = AppCache("myapp")

@cache("expensive")
def expensive_function():
    return calculator()

More Example usage:

from app_json_file_cache import AppCache
cache = AppCache("myapp")

@cache("expensive", vary=VERSION)
def expensive_function(param):
    return calculator(param)

Caveats

  • Names must be unique per app. If you reuse names, chaos ensues.
  • Each set of function parameter values creates a new file. This may lead to too many files in a directory on some systems.
  • Mixing positional and keyword arguments is not supported
  • It’s your responsibility that return values are serializable to JSON.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
app_json_file_cache-0.1.2-py2.py3-none-any.whl (5.3 kB) Copy SHA256 hash SHA256 Wheel py2.py3
app_json_file_cache-0.1.2.tar.gz (3.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page