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.

Source Distribution

app_json_file_cache-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

app_json_file_cache-0.1.0-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file app_json_file_cache-0.1.0.tar.gz.

File metadata

  • Download URL: app_json_file_cache-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2+

File hashes

Hashes for app_json_file_cache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4ecc244f2654f42a999544822ae4d548132a0f4357f65979857d8072917a853a
MD5 5564241d59356cab96d2b6cbc0becaac
BLAKE2b-256 db0f05c4b9c205df766ada7d96d2c145c45c2146067a8c798b84face78b581ca

See more details on using hashes here.

File details

Details for the file app_json_file_cache-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: app_json_file_cache-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2+

File hashes

Hashes for app_json_file_cache-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e691f868c6832f131a8b5071f0289a570da21cfdf6e476b1da1b0dea3691a277
MD5 d2b8af33920f7718dbf777fe82c501fb
BLAKE2b-256 93f19532379388cb1eb541623d9309b803393e3c6a6ea30c19116f96f6eef6d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page