A robust, performance-focused caching library for Python backends with FastAPI integration
Project description
🚀 YokedCache
High-Performance Caching for Modern Python Applications
Intelligent caching with automatic invalidation, fuzzy search, and seamless FastAPI integration
🎯 Why YokedCache?
Traditional caching solutions require manual cache management and lack intelligent invalidation. YokedCache solves this with:
🔄 Smart Auto-Invalidation - Automatically detects database changes and invalidates related caches
⚡ Zero-Code Integration - Drop-in replacement for your existing database dependencies
🎯 Intelligent Tagging - Group and invalidate related caches effortlessly
🔍 Fuzzy Search - Find cached data with approximate matching
📊 Performance Insights - Built-in metrics and monitoring tools
⚡ Quick Start
pip install yokedcache
from fastapi import FastAPI, Depends
from yokedcache import cached_dependency
app = FastAPI()
# Replace your database dependency
cached_get_db = cached_dependency(get_db, ttl=300)
@app.get("/users/{user_id}")
async def get_user(user_id: int, db=Depends(cached_get_db)):
# Your existing code - no changes needed!
return db.query(User).filter(User.id == user_id).first()
That's it! Your database queries are now cached with automatic invalidation. 🎉
✨ Features
🔄 Smart Invalidation
🎯 Deep Integration
|
🔍 Advanced Features
🖥️ Management Tools
|
📦 Installation
# 🚀 Basic installation
pip install yokedcache
# 🔧 With optional features
pip install yokedcache[sqlalchemy,fuzzy] # Full-featured
# 👨💻 Development
pip install yokedcache[dev]
📖 Documentation
| 📚 Guide | 🔗 Link | 📝 Description |
|---|---|---|
| Quick Start | Getting Started | 5-minute integration guide |
| API Reference | Docs | Complete API documentation |
| Examples | Examples | Real-world usage examples |
| CLI Guide | CLI Usage | Command-line tool documentation |
🎬 Live Demo
from fastapi import FastAPI, Depends
from yokedcache import YokedCache, cached_dependency
app = FastAPI()
cache = YokedCache(redis_url="redis://localhost:6379/0")
# 1️⃣ Wrap your existing database dependency
cached_get_db = cached_dependency(get_db, cache=cache, ttl=300)
@app.get("/users/{user_id}")
async def get_user(user_id: int, db=Depends(cached_get_db)):
# 2️⃣ Your existing code works unchanged!
return db.query(User).filter(User.id == user_id).first()
# 🎉 Automatic caching + invalidation now active!
🔧 Advanced Usage
Configuration with YAML
# cache_config.yaml
default_ttl: 300
key_prefix: "myapp"
tables:
users:
ttl: 3600 # 1 hour for user data
tags: ["user_data"]
invalidate_on: ["insert", "update", "delete"]
Manual Cache Control
from yokedcache import YokedCache, cached
cache = YokedCache()
# Decorator caching
@cached(cache=cache, ttl=600, tags=["products"])
async def get_expensive_data(query: str):
return expensive_db_query(query)
# Manual operations
await cache.set("key", {"data": "value"}, ttl=300, tags=["api"])
data = await cache.get("key")
await cache.invalidate_tags(["products"])
🖥️ CLI Usage
YokedCache includes a powerful CLI for cache management:
# View cache statistics
yokedcache stats --watch
# List cached keys
yokedcache list --pattern "user:*"
# Flush specific caches
yokedcache flush --tags "user_data"
# Search cache contents
yokedcache search "alice" --threshold 80
# Monitor in real-time (JSON output for dashboards)
yokedcache stats --format json
🚀 Performance
| Metric | Improvement | Description |
|---|---|---|
| Database Load | ↓ 60-90% | Automatic query caching |
| Response Time | ↓ 200-500ms | Redis-fast cache hits |
| Memory Usage | Optimized | Efficient serialization |
| Setup Time | < 5 minutes | Drop-in integration |
🏗️ Architecture
graph TB
A[FastAPI App] --> B[YokedCache Wrapper]
B --> C{Cache Hit?}
C -->|Yes| D[Return Cached Data]
C -->|No| E[Query Database]
E --> F[Store in Redis]
F --> G[Return Data]
H[Database Write] --> I[Auto-Invalidation]
I --> J[Clear Related Cache]
🧪 Testing
# Install with dev dependencies
pip install yokedcache[dev]
# Run tests
pytest
# Run with coverage
pytest --cov=yokedcache
# Test specific functionality
pytest tests/test_cache.py::TestAutoInvalidation
🤝 Contributing
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Commit your changes:
git commit -m "feat: add amazing feature" - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
See CONTRIBUTING.md for detailed guidelines.
📊 Project Status
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Redis - For the excellent caching backend
- FastAPI - For the amazing Python web framework
- SQLAlchemy - For database ORM integration
- Python Community - For continuous inspiration and feedback
Made with ❤️ by Project Yoked LLC
If YokedCache helps your project, please consider giving it a ⭐ on GitHub!
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
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 yokedcache-0.1.0.tar.gz.
File metadata
- Download URL: yokedcache-0.1.0.tar.gz
- Upload date:
- Size: 42.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98413f44ba720ac3a5f38191433209d6e158bdc322aa65dc08ca95a22829befd
|
|
| MD5 |
43fd9d7dd3b68fd73fe128cd3b01fe68
|
|
| BLAKE2b-256 |
d71ad5bb84ed32a70f25544f7c98633a1ae9b250227e4020ebb00ad842ba5668
|
File details
Details for the file yokedcache-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yokedcache-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9fa22a5e4ae5e621301bbea86c68500f45b4f14285f5d7ba7f81a7536355cb3
|
|
| MD5 |
b8d2a7fd75aed671afbe6f545d60b111
|
|
| BLAKE2b-256 |
8b9866bec4a3de081129634c6c00c645e7387c5db22c925cddf57d0ff7cfe78e
|