fscacher
Caching solution for functions that operate on the file system.
Installation
pip install <path to repository>
Usage
Simple usage:
from fscacher import Cache
cache = Cache(cache_path)
fn = cache.memoize(expensive_fn)
result = fn("arg1", "arg2")
When fn is called the first time, the function expensive_fn is evaluated
and its return value is serialized and stored at cache_path. Subsequent
calls to fn deserializes the stored result instead of re-evaluating
expensive_fn.
Optional arguments to memoize include:
key: Function with arguments(func, args, kwargs)and return value of typestr, used to create the function call signaturedump: Function with arguments(return_value, filename)and no return value for serializing the result ofexpensive_fnload: Function with arguments(filename, )for de-serializing the binary data on disk as a return valuedigest: Function with arguments(stream, )and return value of typestrfor digesting function call signature as well as the contents of serialized filesprotocol: Use predefined functions forkey,dump,loadanddigest. A list of known protocol schemes are presented below. If both protocol and explicit functions are set, the explicit functions takes presedence.
If any of the arguments key, dump, load or digest are set to
"default", the functions defined by the cache.defaults dict are used
instead.
Default key function is constructed as follows:
- Arguments and keyword arguments (both keys and values) are converted to
string by the
strfunction. Numpy arrays are converted to lists before conversion. - Any arguments which are too long (> 22 chars) or contain invalid characters
(
= \/:*?"<>|) are utf-8 encoded and converted to a 64-bit truncated sha256 hash. - Keyword arguments are joined as key-value pairs of the form
k=v. - If short enough, the key is the function name followed by the space-separated argument list. If too long, the key is the function name followed by the full sha256 hash of the space-separated argument list.
Default dump and load functions are from the python pickle module.
Default digest function is sha256.
Implemented protocols include:
filename/<suffix>: Return value is interpreted as the name of a temporary file, which should have the suffix<suffix>, including any leading dot.keyis default key, except that<suffix>is appended.dumpmoves the file to the index location.loadreturns the file name as a string.filehash/<suffix>: Return value is interpreted as the name of a temporary file, which should have the suffix<suffix>, including any leading dot.keyis default key with the suffix.hashappended.dumpcomputes the hash of the temporary file and renames it to the hash value (unless already present). Thereafter, it copies the file (as a hardlink if possible) to the location specified bykey, except that.hashis replaced by<suffix>. Finally, the hash is stored as a string (lowercase hex) at the location specified bykey(the index location).loadreturns the contents of the file at the index location and interprets it as apathlibpath. In the end, this protocol works likefilename/<suffix>, except that multiple function calls can be mapped to the same file if their return value has equal contents.
Metadata
Release files for semantic-fscacher 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| semantic-fscacher-0.3.0.tar.gz | 4.7 kB | Without provenance | Details for semantic-fscacher-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| semantic_fscacher-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for semantic_fscacher-0.3.0-py3-none-any.whl |
Total release size: 9.4 kB
Release files / semantic-fscacher-0.3.0.tar.gz
| Download URL | semantic-fscacher-0.3.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aacb07381b81c4a01d9793d7b70a28f844d60ab3487c9e4f6a79c1bfdc6c5a37
|
|
BLAKE2b-256 checksum How to use checksums |
21c2813c96b57b8f5667ccb9e5d25596b42d3b9d32fd6394d37cbe11e931baeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Release files / semantic_fscacher-0.3.0-py3-none-any.whl
| Download URL | semantic_fscacher-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
55fb294956afd9be2b351c1f571cda56250ef8e8c5d572a4cddba24b9de7a333
|
|
BLAKE2b-256 checksum How to use checksums |
d7df7007f848002f48513d9445527722f94e7da9bba65343875ccf9923c8ef21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
|
Security for semantic-fscacher 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.