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.2.tar.gz (3.3 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.2-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: app_json_file_cache-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 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.2.tar.gz
Algorithm Hash digest
SHA256 120c404789fb99907b3e8878d55cbfcff2c6e0bf14943a5c14a33dcf98eee9fd
MD5 afe05b2511987823c2b50ebef503a6a7
BLAKE2b-256 be08b55ade1681662def16ccc76e27dd330ebf4b518d2a0a008ecf49a09debdd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: app_json_file_cache-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 06cf03bc95180eb64061f4a9ec0315bdc279a83f2556076dfbe864d065802d0c
MD5 c759c1b5eaea7b6cdbf76603cb7c5928
BLAKE2b-256 4c4596d0fac0f29d4d39869e28fefc6504d7a126f73c4a0d01f69e96abf417b6

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