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.3.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.3-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: genericache-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 60283c86e90cc7bdc9d552bd080640a058ba323c2f153b899cb0468f5039dd2b
MD5 8be59c25bc1d290fb66f8be6a49cb97f
BLAKE2b-256 0143bbc083714ea9e008f715dd4d546b8b286613fa2be114f9689bb303f46fa4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genericache-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 332d8eebb61a9b4945eb6a291aafd6fbe181ce70fd8c625c19a757e07090068f
MD5 f721ad4c992ccedca07ea4bac9ff1ebf
BLAKE2b-256 42e2cd14e98c7c5defc839252de424c39d8163ea5083f0b5d23dce8e014e9c2b

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