mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
Fix in memory example
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# pyright: reportGeneralTypeIssues=false
|
# pyright: reportGeneralTypeIssues=false
|
||||||
from typing import Dict, Optional
|
from contextlib import asynccontextmanager
|
||||||
|
from typing import AsyncIterator, Dict, Optional
|
||||||
|
|
||||||
import pendulum
|
import pendulum
|
||||||
import uvicorn
|
import uvicorn
|
||||||
@@ -11,7 +12,13 @@ from pydantic import BaseModel
|
|||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import JSONResponse, Response
|
from starlette.responses import JSONResponse, Response
|
||||||
|
|
||||||
app = FastAPI()
|
@asynccontextmanager
|
||||||
|
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||||
|
FastAPICache.init(InMemoryBackend())
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(lifespan=lifespan)
|
||||||
|
|
||||||
ret = 0
|
ret = 0
|
||||||
|
|
||||||
@@ -119,10 +126,5 @@ def namespaced_injection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@app.on_event("startup")
|
|
||||||
async def startup():
|
|
||||||
FastAPICache.init(InMemoryBackend())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run("main:app", reload=True)
|
uvicorn.run("main:app", reload=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user