File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 11# pyright: reportGeneralTypeIssues=false
2- from typing import Dict , Optional
2+ from contextlib import asynccontextmanager
3+ from typing import AsyncIterator , Dict , Optional
34
45import pendulum
56import uvicorn
1112from starlette .requests import Request
1213from starlette .responses import JSONResponse , Response
1314
14- app = FastAPI ()
15+ @asynccontextmanager
16+ async def lifespan (_ : FastAPI ) -> AsyncIterator [None ]:
17+ FastAPICache .init (InMemoryBackend ())
18+ yield
19+
20+
21+ app = FastAPI (lifespan = lifespan )
1522
1623ret = 0
1724
@@ -119,10 +126,5 @@ def namespaced_injection(
119126 }
120127
121128
122- @app .on_event ("startup" )
123- async def startup ():
124- FastAPICache .init (InMemoryBackend ())
125-
126-
127129if __name__ == "__main__" :
128130 uvicorn .run ("main:app" , reload = True )
You can’t perform that action at this time.
0 commit comments