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.1.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.1.tar.gz.
File metadata
- Download URL: genericache-0.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dbad376c679866a974cb5d86ce8a030c1234362f4876ecb90db1b21f4abc80a
|
|
| MD5 |
99af2b16d3735284c751714664dc31d1
|
|
| BLAKE2b-256 |
db6a9b11da339a4be27624bcc10b22039361216972cf816b233ccb24ea8501dc
|
File details
Details for the file genericache-0.1.1-py3-none-any.whl.
File metadata
- Download URL: genericache-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1210e3358c35fd80ee718920093d050c0bf108296a89b9a7ce03f59313698d69
|
|
| MD5 |
a01579baff85b55eee1401ea5c00800e
|
|
| BLAKE2b-256 |
5dabe6ded5090ba6eb246dac8df370f846259fe31c34af99c436826e7344361d
|