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.2.0.tar.gz
(6.4 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.2.0.tar.gz.
File metadata
- Download URL: genericache-0.2.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f67e611cdb0c7b23523d00053be3cafdbef44eb0beab04a285695233d268c2d
|
|
| MD5 |
1afa993c97b6b67ab596e246a3775687
|
|
| BLAKE2b-256 |
63368ebc36b1075a12097954b03792cfa8126b992ba3967eaf4a0552b6227976
|
File details
Details for the file genericache-0.2.0-py3-none-any.whl.
File metadata
- Download URL: genericache-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8deb93279c92fbf56afe5a3f6872e5ccf92b431224d032c86b6ef0b693f659a2
|
|
| MD5 |
83d3e54c59fccd3026af1c722f7c5c6b
|
|
| BLAKE2b-256 |
ac5e96690c913d16aefe2a6f2fc082b1a569a62a294277e9961130546f5269a1
|