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.1.tar.gz (3.1 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.1-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: app_json_file_cache-0.1.1.tar.gz
  • Upload date:
  • Size: 3.1 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.1.tar.gz
Algorithm Hash digest
SHA256 ed2a75b06b04c787b0fbddaf6e4e081bdd4c750167ac11e43ed91fe46f97dfb8
MD5 5561a3e6fff1806efd02b6bfe0873a5d
BLAKE2b-256 96524f0066365bd368cd7cb6fefe243461c58006ebc97d7e387cd50be7aa4cae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: app_json_file_cache-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5072b645fdad05f96c2cca5e0887c5935674b9e36aa9506213512d2d638ba9b1
MD5 e14c25950e0d84073963973fdfc39686
BLAKE2b-256 50bfb1adead01245cb5c00df84994ba2750dcd0aa6dc62be203bc84b7b4f4f2d

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