add clear method

This commit is contained in:
long2ice
2020-11-03 18:08:06 +08:00
parent dc2ac9cc90
commit e483e0dc55
6 changed files with 40 additions and 2 deletions

View File

@@ -12,7 +12,7 @@ app = FastAPI()
ret = 0
@cache(expire=1)
@cache(namespace="test", expire=1)
async def get_ret():
global ret
ret = ret + 1
@@ -20,11 +20,16 @@ async def get_ret():
@app.get("/")
@cache(expire=2)
@cache(namespace="test", expire=2)
async def index(request: Request, response: Response):
return dict(ret=await get_ret())
@app.get("/clear")
async def clear():
return await FastAPICache.clear(namespace="test")
@app.on_event("startup")
async def startup():
FastAPICache.init(InMemoryBackend(), prefix="fastapi-cache")