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.1.2.tar.gz
(73.2 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.1.2.tar.gz.
File metadata
- Download URL: fastapi_cache_plus-0.1.2.tar.gz
- Upload date:
- Size: 73.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
062b6673e4dc47c087cd89ce8ce6110ef6636c4351e13c2ecb4edbfaccf23d74
|
|
| MD5 |
80efffc1d0ff99a0ebb0efb9ff80fd14
|
|
| BLAKE2b-256 |
0e1d01e656f9da2fb7ebd7c3743caa8d35601228b7bd9876aba9539b0b930ed4
|
File details
Details for the file fastapi_cache_plus-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_cache_plus-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b012ead12212c6b030af7df69e850328a86607f181712399532ec3173b46f396
|
|
| MD5 |
bcedbaf52b7fcd73ef6fb5a406a43b18
|
|
| BLAKE2b-256 |
9cb38554faa0740fdcacdb5998c124611549ed36c220185c64f1b42dd9914ee6
|