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

Uploaded Python 3

File details

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

File metadata

  • Download URL: genericache-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 178f3cb3f14856a141b7aafa6d21824b73efe8c593320427ecf4080a2acddfbd
MD5 58070c263973b0f134a7d1dda4319ba9
BLAKE2b-256 0b1e4518681c01af9d0565c0024d8e0ed22c5e8f89f910fd397c4c83b816a6d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genericache-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23b3386ff74b479985df5d1b580d27d13c670e896c7361090e1ff4f2b65c734a
MD5 bcd4c45837d10bfa56530d4419e79531
BLAKE2b-256 a868d578ce396cb14848d4d15c6025cbf24c6a93989dab28da1afa6ae5f9427c

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