FastAPI simple cache
Project description
FastAPI Cache Plus
This project is a continuation of the project fastapi_cache. Many thanks to Ivan Sushkov (the original author) for their work and contributions.
Implements simple lightweight cache system as dependencies in FastAPI.
Installation
pip install fastapi-cache-plus
Usage example
from fastapi import Depends, FastAPI
from fastapi_cache_plus import caches, close_caches
from fastapi_cache_plus.backends.redis import CACHE_KEY, RedisCacheBackend
app = FastAPI()
def redis_cache():
return caches.get(CACHE_KEY)
@app.get("/")
async def hello(cache: RedisCacheBackend = Depends(redis_cache)):
in_cache = await cache.get("some_cached_key")
if not in_cache:
await cache.set("some_cached_key", "new_value", 5)
return {"response": in_cache or "default"}
@app.on_event("startup")
async def on_startup() -> None:
rc = RedisCacheBackend("redis://redis")
caches.set(CACHE_KEY, rc)
@app.on_event("shutdown")
async def on_shutdown() -> None:
await close_caches()
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
fastapi_cache_plus-0.2.0.tar.gz
(74.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 fastapi_cache_plus-0.2.0.tar.gz.
File metadata
- Download URL: fastapi_cache_plus-0.2.0.tar.gz
- Upload date:
- Size: 74.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
526241a2340a8ecf1ecedefab480da8aec128c4c17d32397d6617d49d6094f81
|
|
| MD5 |
fa18c8fe6239c3d53c36ee3c5d0cae30
|
|
| BLAKE2b-256 |
84ca44243c7bdcc017c2d52397c0ad6fc8330695d8609d06e00175e29f99c4ea
|
File details
Details for the file fastapi_cache_plus-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_cache_plus-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3f243eab144650e86b4d1d28e3234f2ffc4289d21504b04dc9ed6aa399cc1d
|
|
| MD5 |
ff147b0764c56576e245403204db10e8
|
|
| BLAKE2b-256 |
7e7ec5831ceae4f950547b336b579900682b66e519ede23a97df7577488079e4
|