上传者: 42118011
|
上传时间: 2022-03-09 16:32:43
|
文件大小: 14KB
|
文件类型: -
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