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
Release history Release notifications | RSS feed
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91691330dee2b082ebe95fe68aa0d019c9a218d47d9e7c0fe02204956da77da2
|
|
| MD5 |
105c15ae1817f0ddcdc99e61677965c5
|
|
| BLAKE2b-256 |
aec5881ceea06b2efd2e421de4a7988e822d815bd826bde810e4968e1c13484d
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ca745dbacc183662c1a2824272384beade70ffaaa3a5f5c4f792497f87f64db
|
|
| MD5 |
d84e27529b258c7b0d613c28988a6f1f
|
|
| BLAKE2b-256 |
54021bf53a4c6d39443ace28ec74904888e3fd4517ef99603f2cbcf142ea77ef
|