Lightweight client package to asynchronously trigger centralized cache invalidation via API
Project description
cache-central-flush
A lightweight, asynchronous Python client for triggering cache invalidation via HTTP API. Perfect for microservices architectures where you need to invalidate distributed caches (Redis, CDN, etc.) without blocking your application.
Features
- ✅ Asynchronous - Fire-and-forget, won't block your application
- ✅ Error-safe - Failures won't crash your application
- ✅ Lightweight - Minimal dependencies (only
requests) - ✅ Thread-safe - Uses daemon threads for background execution
- ✅ Configurable - Works with any cache invalidation API
- ✅ Generic - Not tied to any specific cache provider
Installation
From PyPI
pip install cache-central-flush
From GitHub
pip install git+https://github.com/karantomar207/cache-central-flush
Quick Start
from cache_central_flush import flush_cache
# Trigger cache invalidation asynchronously
flush_cache(
entity_id=123,
entity_type="product",
api_url="https://api.example.com/cache/invalidate",
api_key="your-api-key-here"
)
The function returns immediately and the HTTP request happens in the background.
Parameters
- entity_id (int): The ID of the entity to invalidate
- entity_type (str): Type of entity (e.g., "product", "user", "article")
- api_url (str): Full URL of your cache invalidation API endpoint
- api_key (str): Your API key for authentication
Real-World Example
from cache_central_flush import flush_cache
import os
# Get configuration from environment variables
CACHE_API_URL = os.getenv("CACHE_INVALIDATION_URL")
CACHE_API_KEY = os.getenv("CACHE_API_KEY")
# Example: E-commerce product update
def update_product_price(product_id, new_price):
# Update price in database
db.products.update(product_id, price=new_price)
# Invalidate cache asynchronously (won't block the response)
flush_cache(
entity_id=product_id,
entity_type="product",
api_url=CACHE_API_URL,
api_key=CACHE_API_KEY
)
return {"success": True, "product_id": product_id}
Use Cases
- CDN Cache Invalidation - Clear CDN cache when content updates
- Redis Cache Invalidation - Invalidate Redis keys via HTTP API
- Microservices - Notify cache service when data changes
- Multi-tier Caching - Invalidate multiple cache layers
- Event-driven Architecture - Trigger cache updates asynchronously
Configuration
Use environment variables for better security:
export CACHE_INVALIDATION_URL="https://api.example.com/cache/invalidate"
export CACHE_API_KEY="your-secret-api-key"
API Requirements
Your cache invalidation API should accept:
- Method: POST
- Headers:
x-api-keyfor authentication - Body: JSON with
entity_idandentity_type
Example API endpoint:
@app.post("/cache/invalidate")
def invalidate_cache(request):
api_key = request.headers.get("x-api-key")
# Validate API key...
entity_id = request.json["entity_id"]
entity_type = request.json["entity_type"]
# Invalidate cache...
return {"status": "invalidated"}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - Copyright (c) 2026 Karan Singh Tomar
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 cache_central_flush-2.0.0.tar.gz.
File metadata
- Download URL: cache_central_flush-2.0.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a00b83851f27eb9384ba2725b0ca225607d752139ae2cb75d730a7a75d855e4
|
|
| MD5 |
bf31e95a5d3cfd31eb4132e5c5ea483d
|
|
| BLAKE2b-256 |
69bfcd430f319007557ba7882ae22aed26f7bec928ee29cd392e7b869f3fd9bf
|
File details
Details for the file cache_central_flush-2.0.0-py3-none-any.whl.
File metadata
- Download URL: cache_central_flush-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc9b5f7d26a6e7389b71c65e183b96021b822ff106ce7a73ec3788719c818e2f
|
|
| MD5 |
57a6072e2edd2773080334be64ce956c
|
|
| BLAKE2b-256 |
8b32caa7882e6a24b5292e99efb7a406b41ce50b92d2169666993285c0870ed5
|