mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
feat: cache response obj add test case
This commit is contained in:
@@ -2,7 +2,7 @@ import pendulum
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
from starlette.responses import Response, JSONResponse
|
||||
|
||||
from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.backends.inmemory import InMemoryBackend
|
||||
@@ -42,6 +42,7 @@ async def get_date():
|
||||
async def get_datetime(request: Request, response: Response):
|
||||
return {"now": pendulum.now()}
|
||||
|
||||
|
||||
@app.get("/sync-me")
|
||||
@cache(namespace="test")
|
||||
def sync_me():
|
||||
@@ -50,6 +51,12 @@ def sync_me():
|
||||
return 42
|
||||
|
||||
|
||||
@app.get("/cache_response_obj")
|
||||
@cache(namespace="test", expire=5)
|
||||
async def cache_response_obj():
|
||||
return JSONResponse({"a": 1})
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
FastAPICache.init(InMemoryBackend())
|
||||
|
||||
Reference in New Issue
Block a user