mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
add clear method
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user