Skip to content

Commit 5ba03ca

Browse files
Correct example in README.md
1 parent 865dba1 commit 5ba03ca

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ from fastapi_cache.decorator import cache
6464

6565
from redis import asyncio as aioredis
6666

67-
app = FastAPI()
67+
68+
@asynccontextmanager
69+
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
70+
redis = aioredis.from_url("redis://localhost")
71+
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
72+
yield
73+
74+
75+
app = FastAPI(lifespan=lifespan)
6876

6977

7078
@cache()
@@ -76,12 +84,6 @@ async def get_cache():
7684
@cache(expire=60)
7785
async def index():
7886
return dict(hello="world")
79-
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
8587
```
8688

8789
### Initialization

0 commit comments

Comments
 (0)