Skip to main content

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


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.4.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

genericache-0.1.4-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file genericache-0.1.4.tar.gz.

File metadata

  • Download URL: genericache-0.1.4.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for genericache-0.1.4.tar.gz
Algorithm Hash digest
SHA256 bf3dee44965263fbe0e14479d94ec33ce7200d144f5bb37505735df003aecb24
MD5 694b6173686fc3c467402d7594abda7e
BLAKE2b-256 7d663e89931292977ba3aed2412a54c532b333448177e2f36ea886f594250469

See more details on using hashes here.

File details

Details for the file genericache-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for genericache-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 28b2709b4ca6c09c51f52f8fdc3931139b963cfce872beb6c0e1738ab5baad93
MD5 392e0a1286c7096802e1330d9270d620
BLAKE2b-256 4248af06689180fb115239759bfd133a2cb30f7aa445e9c7456eb4cc957bbea8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page