Skip to main content

HTTP caching library for Python that supports in-memory and persistent storage, designed to speed up repeated requests and reduce redundant network calls.ea

Project description

cachio

cachio is an HTTP caching library for Python that enables efficient storage and retrieval of HTTP responses in both memory and on disk. It is designed to improve performance, reduce redundant network requests, and support persistent caching.

Features

  • In-Memory Cache Store responses in memory for fast, low-latency retrieval.

  • Disk Cache Persist responses on disk for long-lived caching across sessions.

  • LRU Eviction Implements a Least Recently Used (LRU) strategy to manage cache size and memory usage effectively.

  • Full Response Storage Maintains the complete HTTP response, including headers, status code, and raw body content.

Use Cases

  • Web Crawlers Prevent re-downloading the same pages multiple times.

  • API Clients Reduce API call frequency and improve response times.

  • Testing Replay cached responses to simulate server behavior without hitting external services.

  • Offline Access Access previously fetched data even when a network connection is unavailable.

Installation

pip install cachio

or if using uv

uv add  cachio

Example Usage

from diskcache import Cache
from httpcache import HTTPCache

if __name__ == "__main__":
    c = Cache("cache")
    cache = HTTPCache(storage=c)

    response = cache.get("https://www.example.com/index.html")

Notes:

  • The first request fetches the response from the network.
  • Subsequent requests for the same URL are served from the cache.
  • You can replace Cache("cache") with an in-memory cache if persistence is not required.

Architecture Overview

+------------------+
|   User Request   |
+--------+---------+
         |
         v
+------------------+      Cache Lookup
|  HTTPCache Core  |<--------------------+
+--------+---------+                     |
         |                               |
         v                               |
  +------+-------+      Miss             |
  | In-Memory LRU|---------------------->|
  +------+-------+                        |
         |                                |
         v                                |
  +------+-------+      Miss               |
  |   DiskCache  |------------------------>|
  +------+-------+                         |
         |                                 |
         v                                 |
  +------+-------+                         |
  |   HTTP Fetch |------------------------>|
  +--------------+                         

Description:

  1. In-Memory LRU Cache: Fast retrieval for frequently accessed responses.
  2. Disk Cache: Fallback for responses that are no longer in memory but were cached previously.
  3. HTTP Fetch: Only triggered if the response is not available in memory or disk.

NB: This repo is under construction and isn't suitable for production yet...

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

cachio-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

cachio-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cachio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f71844046cae6eb7d2556d7963ce743ff4d830393513cdbe0dc118af96a34ca4
MD5 f98c4a38db6090af65e2489a147d26a4
BLAKE2b-256 6777b376709b5b501c8cc140a2bf695d5c474bda37504f129ef347a521da0221

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cachio-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for cachio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60224d38b678374451c8cef973b4c8a88167e808b3643ae350b8b43d2f0daaff
MD5 e078dfb38ce44242b10746f6d518b930
BLAKE2b-256 9fa41daa09d7576d2229bcccf9a94bd26ab6f6fe430dbbbeb70d56dc6cf23869

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