A thread-safe, process-safe cache for slow data fetching operations
Project description
Sharedcache
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.0.3.tar.gz
(5.9 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.0.3.tar.gz.
File metadata
- Download URL: genericache-0.0.3.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d4676ae6757679715b7afec46d2fe7241ddce92cb51aae6a16b26118e1fe7e3
|
|
| MD5 |
91cc4366ab6288363704e2f2175c9e94
|
|
| BLAKE2b-256 |
6345453a257c1f55a55fd85634eb1b6f106151c1e6b521cb758c1e0cc0428dee
|
File details
Details for the file genericache-0.0.3-py3-none-any.whl.
File metadata
- Download URL: genericache-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49e25092ea05d965acbe14d4b5828b85bf6cd4196d5448f022dc7b4625065060
|
|
| MD5 |
80c143cbd161d09dca44aa8e8953ba6f
|
|
| BLAKE2b-256 |
fe7caa654c334620bd52c988ade50c0c3d7288e0f0e0f4314d4032ed441b32c0
|