Skip to main content

Backend-swappable caching layer for the dd-* ecosystem

Project description

dd-cache

Backend-swappable caching layer for the dd-* ecosystem.

Install

pip install -e .           # core (memory + disk)
pip install -e ".[redis]"  # add Redis support
pip install -e ".[dev]"    # + pytest

Quick start

from dd_cache import InMemoryCache, DiskCache

# In-process, TTL-aware
with InMemoryCache() as cache:
    cache.set("key", {"data": 42}, ttl=60)
    value = cache.get("key")

# Persistent SQLite
with DiskCache(".cache/myapp.db") as cache:
    result = cache.get_or_set("expensive_key", lambda: run_expensive_query())

Adapters

Class Backend Persistence TTL Extra deps
InMemoryCache dict process lazy none
DiskCache SQLite file lazy none
RedisCache Redis server native redis

API

cache.get(key)                    # → Any | None
cache.set(key, value, ttl=None)   # ttl in seconds
cache.delete(key)                 # → bool
cache.exists(key)                 # → bool
cache.clear()
cache.stats()                     # → CacheStats
cache.get_or_set(key, fn, ttl=None)

See docs/DESIGN.md for architecture details.

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

dd_cache-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

dd_cache-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dd_cache-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for dd_cache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 91691330dee2b082ebe95fe68aa0d019c9a218d47d9e7c0fe02204956da77da2
MD5 105c15ae1817f0ddcdc99e61677965c5
BLAKE2b-256 aec5881ceea06b2efd2e421de4a7988e822d815bd826bde810e4968e1c13484d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dd_cache-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for dd_cache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ca745dbacc183662c1a2824272384beade70ffaaa3a5f5c4f792497f87f64db
MD5 d84e27529b258c7b0d613c28988a6f1f
BLAKE2b-256 54021bf53a4c6d39443ace28ec74904888e3fd4517ef99603f2cbcf142ea77ef

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