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.0.tar.gz (5.9 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.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for genericache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb2fc1abb854530268751ab12b1c5267bf486ddc16d7bb22ea0270c6b76b344a
MD5 39db7755174133660ceacd5dfbeb554f
BLAKE2b-256 b6c31fabdb4d2789328dbeb3e327fccf56857bf7c70e37279cdef5081d353726

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genericache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e7df1e116f6099c25652ec2dda5cf0c50ce291096bc684b90e0211f22dbd3b0
MD5 4a86c91cbdaea5a7ef69c15fe9ef2fb2
BLAKE2b-256 c809ed40b8c79163a8b209b7d3c1f6250c9f148b0a2e14b0dcedae35aca54b8c

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