Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Discussion options

You must be logged in to vote

To avoid overheads caused by using sync dependency, you can either use async alternative of lru_cache (alru_cache (https://github.com/aio-libs/async-lru)) or wrap your cached function with async function:

@lru_cache
def get_settings_sync():
    return Settings()


async def get_settings():
    return get_settings_sync()


@app.get("/info")
async def info(settings: Annotated[Settings, Depends(get_settings)]):
    return {
        "app_name": settings.app_name,
        "admin_email": settings.admin_email,
        "items_per_user": settings.items_per_user,
    }

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@eddy2by4
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@YuriiMotov
Comment options

@alexandrubese
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
4 participants