A thread-safe, process-safe cache for slow data fetching operations
Project description
Genericache
A thread-safe, process-safe cache for slow fetching operations, like web requests.
Usage
from genericache import DiskCache, UrlDigest
from pathlib import Path
from typing import Iterable
from hashlib import sha256
def my_fetch(url: str) -> Iterable[bytes]:
import httpx
return httpx.get(url).raise_for_status().iter_bytes(4096)
def url_hasher(url: str) -> UrlDigest:
return UrlDigest.from_str(url)
cache = DiskCache(
cache_dir=Path("/tmp/my_cache"),
fetcher=my_fetch,
url_hasher=url_hasher,
)
reader, contents_digest = cache.fetch("https://www.ilastik.org/documentation/pixelclassification/snapshots/training2.png")
assert sha256(reader.read()).digest() == contents_digest.digest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
genericache-0.1.2.tar.gz
(6.8 kB
view details)
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 genericache-0.1.2.tar.gz.
File metadata
- Download URL: genericache-0.1.2.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3d84d24162b4ef5a668b5a732998c8fe7733be12776ee7220b70740ab75419f
|
|
| MD5 |
5289038cb0e521f534d213b982935e32
|
|
| BLAKE2b-256 |
976a7842bb86898b601861006a38fb7013dcf8a394fb7f9121c6cb717e7448a6
|
File details
Details for the file genericache-0.1.2-py3-none-any.whl.
File metadata
- Download URL: genericache-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c46eee8336422d8114b43ce2e386407e8c32d842647442b5d60db7303e0bcfa
|
|
| MD5 |
af9bba409848804c80173c949cbb3797
|
|
| BLAKE2b-256 |
042c7dd94b9e11e49df77e89d8921d90d9ab6d886a56285eebfcb58549b191b3
|