FastAPI缓存
将简单的轻量级缓存系统实现为FastAPI中的依赖项。
安装
pip install fastapi-cache
用法示例
from fastapi import Depends , FastAPI
from fastapi_cache import caches , close_caches
from fastapi_cache . 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
1