Skip to main content

quick_cache

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.

Metadata

Release files for quick-cache 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quick-cache 0.3.1
File Size Uploaded
quick_cache-0.3.1.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quick-cache 0.3.1
File Interpreter ABI Platform
quick_cache-0.3.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 14.5 kB

Release files / quick_cache-0.3.1.tar.gz

Download URL quick_cache-0.3.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c600bdd266b4964728f6bcb466327ed7323487b854fdbdd48c15170f1f81327e
BLAKE2b-256 checksum
How to use checksums
60b6cd7e97cf4affb91c92a9680aea04260d3ce96a46b2a964becf5086ccbe41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / quick_cache-0.3.1-py2.py3-none-any.whl

Download URL quick_cache-0.3.1-py2.py3-none-any.whl
Size 7.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9599c99f9e1f7602790b85e233c49a970f2121c5895e218453fbcee1939f5099
BLAKE2b-256 checksum
How to use checksums
7b43b8cc225f451c8906d358e155d25fd2fafc0eb9d3646befacf14d4f3a3341
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

3 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page