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.1.tar.gz
(72.4 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.1.tar.gz.
File metadata
- Download URL: fastapi_cache_plus-0.1.1.tar.gz
- Upload date:
- Size: 72.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abdaa73943d7dd30e6ce85b723036d8db8d005282d742e89b8d5323077856d9b
|
|
| MD5 |
c772ba46435fbf4995948df58be8ef0e
|
|
| BLAKE2b-256 |
fff1e8d06c816d5d5add76cbda3e710f2a18e5072266848a9c50a6c94c6bbb8e
|
File details
Details for the file fastapi_cache_plus-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_cache_plus-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b8aa0252b1a0ffb1d7c47ac908b4db55b6282beb3303bab4cf72072ae199c29
|
|
| MD5 |
c5bd806040b2a1d47e4297860b7f3d03
|
|
| BLAKE2b-256 |
984f1dda9b330d8c040a6ef65727279b22d2d5dca6ca4fc4a1a65cb44b2be21c
|