Skip to main content

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 fetchcache 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.0.1.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.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for genericache-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1951c2adf660afb392e74be3bade01484fe1e50ccf86654415314bccf442e8fc
MD5 02e5c8a9c83c5c4a87d0e54fe51f5dee
BLAKE2b-256 c95aa95f35504ba3bdee9414ca67590a52ce76ae18b1a7bed3a535b5ac1a545b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genericache-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 167c5535d002952a3c9f9ff6f63323a45a900eb8bfa7421b409da43f9717fda2
MD5 ef16ffafe495316cff3280dcec5b856a
BLAKE2b-256 f43d92bfb8d3ed2b09fef124ec1e6e63582bd4d4e40228e479b709a50b333e6f

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