mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
Fix default json coder for datetime.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from datetime import date, datetime
|
||||
|
||||
import aioredis
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
@@ -31,6 +33,18 @@ async def clear():
|
||||
return await FastAPICache.clear(namespace="test")
|
||||
|
||||
|
||||
@app.get("/date")
|
||||
@cache(namespace="test", expire=20)
|
||||
async def get_data(request: Request, response: Response):
|
||||
return date.today()
|
||||
|
||||
|
||||
@app.get("/datetime")
|
||||
@cache(namespace="test", expire=20)
|
||||
async def get_datetime(request: Request, response: Response):
|
||||
return datetime.now()
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
redis = aioredis.from_url(url="redis://localhost")
|
||||
|
||||
Reference in New Issue
Block a user