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 @@ -64,7 +64,15 @@ from fastapi_cache.decorator import cache
6464
6565from 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 )
7785async 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
You can’t perform that action at this time.
0 commit comments