We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 91ba6d7 + f203d23 commit 865dba1Copy full SHA for 865dba1
README.md
@@ -51,6 +51,9 @@ or
51
### Quick Start
52
53
```python
54
+from collections.abc import AsyncIterator
55
+from contextlib import asynccontextmanager
56
+
57
from fastapi import FastAPI
58
from starlette.requests import Request
59
from starlette.responses import Response
@@ -74,12 +77,11 @@ async def get_cache():
74
77
async def index():
75
78
return dict(hello="world")
76
79
-
-@app.on_event("startup")
-async def startup():
80
+@asynccontextmanager
81
+async def lifespan(_: FastAPI) -> AsyncIterator[None]:
82
redis = aioredis.from_url("redis://localhost")
83
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
84
+ yield
85
```
86
87
### Initialization
0 commit comments