mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
feat: merge master
This commit is contained in:
@@ -4,12 +4,14 @@ import pendulum
|
||||
import redis.asyncio as redis
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from redis.asyncio.connection import ConnectionPool
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response, JSONResponse
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from redis.asyncio.connection import ConnectionPool
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
|
||||
from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.backends.redis import RedisBackend
|
||||
from fastapi_cache.coder import PickleCoder
|
||||
@@ -18,10 +20,11 @@ from fastapi_cache.decorator import cache
|
||||
app = FastAPI()
|
||||
|
||||
app.mount(
|
||||
path='/static',
|
||||
app=StaticFiles(directory='./'), name='static',
|
||||
path="/static",
|
||||
app=StaticFiles(directory="./"),
|
||||
name="static",
|
||||
)
|
||||
templates = Jinja2Templates(directory='./')
|
||||
templates = Jinja2Templates(directory="./")
|
||||
ret = 0
|
||||
|
||||
|
||||
@@ -65,12 +68,10 @@ async def get_datetime(request: Request, response: Response):
|
||||
return pendulum.now()
|
||||
|
||||
|
||||
@app.get('/html', response_class=HTMLResponse)
|
||||
@app.get("/html", response_class=HTMLResponse)
|
||||
@cache(expire=60, namespace="html", coder=PickleCoder)
|
||||
async def cache_html(request: Request):
|
||||
return templates.TemplateResponse('index.html', {
|
||||
'request': request, "ret": await get_ret()
|
||||
})
|
||||
return templates.TemplateResponse("index.html", {"request": request, "ret": await get_ret()})
|
||||
|
||||
|
||||
@app.get("/cache_response_obj")
|
||||
|
||||
Reference in New Issue
Block a user