Skip to main content

QuickCache is a quick to use and easy to set up cache implementation.

Project description

A quick and easy to use python caching system.

You can install quick_cache via

pip install --user quick_cache

and import it in python using:

from quick_cache import QuickCache

Create the cache object as follows:

def msg(message, *args, **kwargs):
    print(message.format(*args, **kwargs), file=sys.stderr)

cache = QuickCache(base_file, quota=500, ram_quota=100, warnings=msg)

where base_file is an optional file whose content invalidates the cache (ie., when the content of the file changes the cache is invalidated; for large files it might be desirable to use the mtime in the cache object below) and msg is an optional formatting function that prints warnings (by default it’s None which doesn’t print anything; warnings are emitted when the actual computation is faster than reading the results from the cache or if other exceptional situations occur). quota and ram_quota are optional maximal cache sizes, both in RAM and on disk, in MB.

The caching functionality can then be used via:

with cache.get_hnd({
    # object identifying the task to cache
    # can be any combination of keys and values
    "param_a": 5,
    "input_file_c": os.path.getmtime(input_file_c), # for file change time
    ...
}) as hnd:
    if not hnd.has():
        res = hnd.write(do_compute()) # compute your result here
    else:
        res = hnd.read()
# your result is in res

The cache object used for creating the handle uniquely defines the task. The object should contain all parameters of the task and the task computation itself should be deterministic.

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

quick_cache-0.3.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

quick_cache-0.3.1-py2.py3-none-any.whl (7.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file quick_cache-0.3.1.tar.gz.

File metadata

  • Download URL: quick_cache-0.3.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for quick_cache-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c600bdd266b4964728f6bcb466327ed7323487b854fdbdd48c15170f1f81327e
MD5 7db231972988ad6b22fbc2a11dc63e46
BLAKE2b-256 60b6cd7e97cf4affb91c92a9680aea04260d3ce96a46b2a964becf5086ccbe41

See more details on using hashes here.

File details

Details for the file quick_cache-0.3.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for quick_cache-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9599c99f9e1f7602790b85e233c49a970f2121c5895e218453fbcee1939f5099
MD5 35aa52d9139f285dd871a467f0e2df5f
BLAKE2b-256 7b43b8cc225f451c8906d358e155d25fd2fafc0eb9d3646befacf14d4f3a3341

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