mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
Correct example in README.md
This commit is contained in:
16
README.md
16
README.md
@@ -64,7 +64,15 @@ from fastapi_cache.decorator import cache
|
|||||||
|
|
||||||
from redis import asyncio as aioredis
|
from redis import asyncio as aioredis
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||||
|
redis = aioredis.from_url("redis://localhost")
|
||||||
|
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(lifespan=lifespan)
|
||||||
|
|
||||||
|
|
||||||
@cache()
|
@cache()
|
||||||
@@ -76,12 +84,6 @@ async def get_cache():
|
|||||||
@cache(expire=60)
|
@cache(expire=60)
|
||||||
async def index():
|
async def index():
|
||||||
return dict(hello="world")
|
return dict(hello="world")
|
||||||
|
|
||||||
@asynccontextmanager
|
|
||||||
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
|
||||||
redis = aioredis.from_url("redis://localhost")
|
|
||||||
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache")
|
|
||||||
yield
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Initialization
|
### Initialization
|
||||||
|
|||||||
Reference in New Issue
Block a user