Skip to main content

Genericache

A thread-safe, process-safe cache for slow fetching operations, like web requests.

Usage

    from genericache import DiskCache
    from genericache.digest import 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[str].create(
        url_type=str,
        cache_dir=Path("/tmp/my_cache"),
        url_hasher=url_hasher,
    )

    reader, contents_digest = cache.fetch(
        "https://www.ilastik.org/documentation/pixelclassification/snapshots/training2.png",
        fetcher=my_fetch,
    )
    assert sha256(reader.read()).digest() == contents_digest.digest
    assert cache.hits() == 0
    assert cache.misses() == 1

    reader, contents_digest = cache.fetch(
        "https://www.ilastik.org/documentation/pixelclassification/snapshots/training2.png",
        fetcher=my_fetch,
    )
    assert cache.hits() == 1
    assert cache.misses() == 1

Static type checking

Run pyright over the entire project:

    python3 -m scripts.check

Testing

Run the modules inside tests/, e.g.:

uv run --python 3.11 python -m tests.test_disk_cache

You can also run all tests via the run_tests executable module:

    python3 -m scripts.run_tests

Metadata

Release files for genericache 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genericache 0.5.2
File Size Uploaded Provenance Actions
genericache-0.5.2.tar.gz 8.3 kB Without provenance Details for genericache-0.5.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for genericache 0.5.2
File Interpreter ABI Platform Actions
genericache-0.5.2-py3-none-any.whl Python 3 none any Details for genericache-0.5.2-py3-none-any.whl

Total release size: 18.4 kB

Release files / genericache-0.5.2.tar.gz

Download URL genericache-0.5.2.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1bdc21b0471ffd3092c78dbbee2c757ad444baa746073c68068f0f41509d826f
BLAKE2b-256 checksum
How to use checksums
018b9773e74ece19b9fbf1d0f6d78f659091dfb8c4549107e9d95b15b6e8ff5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.5

Release files / genericache-0.5.2-py3-none-any.whl

Download URL genericache-0.5.2-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c922cf07df74280911d79068f43583f86b4d6caee1704d79c779d9fd6547a72
BLAKE2b-256 checksum
How to use checksums
62a13f982f9a8f082760b6970ad6c25573bb2526dc180b695f0f50fa3f392d60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.5

Security for genericache 0.5.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page