Skip to content

Commit c76f6d1

Browse files
Fix cache decorator example with missing db dependency injection
1 parent 5e1e70f commit c76f6d1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/user-guide/caching/redis-cache.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ The `@cache` decorator provides a simple interface for adding caching to any Fas
2121
### Basic Usage
2222

2323
```python
24-
from fastapi import APIRouter, Request
24+
from fastapi import APIRouter, Request, Depends
25+
from sqlalchemy.orm import Session
2526
from app.core.utils.cache import cache
27+
from app.core.db.database import get_db
2628

2729
router = APIRouter()
2830

2931
@router.get("/posts/{post_id}")
3032
@cache(key_prefix="post_cache", expiration=3600)
31-
async def get_post(request: Request, post_id: int):
33+
async def get_post(request: Request, post_id: int, db: Session = Depends(get_db)):
3234
# This function's result will be cached for 1 hour
3335
post = await crud_posts.get(db=db, id=post_id)
3436
return post

0 commit comments

Comments
 (0)