Caching of the function results in a file.
Project description
Pickle function cache
Allows for caching of the results of function calls in a
file using pickle (builtin shelve did not
work for some reason and marshal was not considered;
json was not able to serialize all the things I needed).
- the file read happens only once per process per filename (all the function caches in the same cache file are loaded once)
- if the result is not found in the cache, the result is computed using the original function and is written into the cache file and to the runtime cache.
- if the result for the same set of arguments is requested and found the original function is not called but the cached result is returned.
Usage
from pickle_function_cache import cache_responses
@cache_responses("cache.dat")
def f1(param1, param2):
... # take a lot of time
@cache_responses("cache.dat")
def f2(param1, param2, param3):
... # take a lot of time
# use function normally ...
- when first called,
f1(1,2)computes the result using the original, f1 - afterwards
f1(1,2)returns the cached result, omitting the function call - if you call
f2(1,2,3), it will be no trouble because function caches are stored separately per function name in the same file (note: cached function names should be unique)
Configuration
You can set the env var OMIT_PICKLE_FUNCTION_CACHE to either 1 or true
to disable the cache at compile time without changing the code.
Performance
The cache was tested on a small set of quick functions and a small test list of examples and did not introduce a significant overhead. Probably, if the chosen functions for cache were more computationally intensive, we would see a speed-up because of the cache.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pickle_function_cache-0.1.3.tar.gz.
File metadata
- Download URL: pickle_function_cache-0.1.3.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32464ca83e854df3d3d0240f3614fc5a0a1aab7bd6e00958b9c734f9fe0799dc
|
|
| MD5 |
3708ba47608f2efe301f12717e7a3c45
|
|
| BLAKE2b-256 |
415e5d3d2f1fccb1049702607fa8b51bc82dd3cbafb1429603edd05ce33fa67c
|
File details
Details for the file pickle_function_cache-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pickle_function_cache-0.1.3-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55dd8431994c29eeae7a24b5af94a24c3c19260e56ad574f7f2ba657adf940e0
|
|
| MD5 |
ddacfc0057c9ff18345ec1f3d8b75d07
|
|
| BLAKE2b-256 |
7897732e97acb7d95243bf1e20cdb3bfd6727e433ef98e05ca7a9905aa91798a
|