我应该缓存 FastAPI 依赖项吗?

时间:2021-07-20 17:10:47

标签: fastapi

在我的应用程序中,我计划有一种方法来动态构建依赖项,如下所示:

def authorized_to(result):

    def dependency(
            r=Depends(result),
            token: Token = Depends(make_current_token_dep(auth_any))
    ):
        if r is True:
            return token

        raise HTTPException(
            status_code=HTTP_403_FORBIDDEN, detail="Action not allowed"
        )

    return Depends(dependency)

问题是,鉴于依赖项是在函数内定义的函数,让 FastAPI 自动缓存它是个好主意还是应该禁用此依赖项的缓存?

0 个答案:

没有答案
相关问题