diff --git a/backend/api/api.py b/backend/api/api.py index c4bb2e2..9af6f04 100644 --- a/backend/api/api.py +++ b/backend/api/api.py @@ -1,8 +1,9 @@ from fastapi import APIRouter -from backend.api.endpoints import analyze, lookup, submit +from backend.api.endpoints import analyze, cache, lookup, submit api_router = APIRouter() api_router.include_router(analyze.router, prefix="/analyze", tags=["analyze"]) api_router.include_router(submit.router, prefix="/submit", tags=["submit"]) api_router.include_router(lookup.router, prefix="/lookup", tags=["lookup"]) +api_router.include_router(cache.router, prefix="/cache", tags=["cache"]) diff --git a/backend/api/endpoints/analyze.py b/backend/api/endpoints/analyze.py index 8fbb92a..4c80f87 100644 --- a/backend/api/endpoints/analyze.py +++ b/backend/api/endpoints/analyze.py @@ -42,7 +42,7 @@ def cache_response( expire: int = settings.REDIS_EXPIRE, field: str = settings.REDIS_FIELD, ): - redis.hset(name=response.id, key=field, value=response.model_dump_json()) + redis.hset(name=field, key=response.id, value=response.model_dump_json()) if expire > 0: redis.expire(name=response.id, time=expire) diff --git a/backend/api/endpoints/cache.py b/backend/api/endpoints/cache.py new file mode 100644 index 0000000..2c73101 --- /dev/null +++ b/backend/api/endpoints/cache.py @@ -0,0 +1,21 @@ +from fastapi import APIRouter, HTTPException, status + +from backend import deps, settings + +router = APIRouter() + + +@router.get( + "/", + response_description="Return cache keys", + summary="Get analysis cache keys", + description="Try to get analysis cache keys", +) +async def cache_keys(optional_redis: deps.OptionalRedis) -> list[str]: + if optional_redis is None: + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Redis cache is not enabled", + ) + + return optional_redis.hkeys(settings.REDIS_FIELD) # type: ignore diff --git a/backend/api/endpoints/lookup.py b/backend/api/endpoints/lookup.py index d1a4bb6..b796bb6 100644 --- a/backend/api/endpoints/lookup.py +++ b/backend/api/endpoints/lookup.py @@ -18,7 +18,7 @@ async def lookup(id: str, *, optional_redis: deps.OptionalRedis) -> schemas.Resp detail="Redis cache is not enabled", ) - got: bytes | None = optional_redis.hget(name=id, key=settings.REDIS_FIELD) # type: ignore + got: bytes | None = optional_redis.hget(key=id, name=settings.REDIS_FIELD) # type: ignore if got is None: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 6cdd3b3..aba8ff4 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -18,5 +18,9 @@ export const API = { async lookup(id: string): Promise { const res = await client.get(`/api/lookup/${id}`) return res.data + }, + async getCacheKeys(): Promise { + const res = await client.get(`/api/cache/`) + return res.data } } diff --git a/frontend/src/components/Cache.vue b/frontend/src/components/Cache.vue new file mode 100644 index 0000000..fb35c34 --- /dev/null +++ b/frontend/src/components/Cache.vue @@ -0,0 +1,46 @@ + + + diff --git a/frontend/src/components/Navbar.vue b/frontend/src/components/Navbar.vue index 047823f..3ac2b9c 100644 --- a/frontend/src/components/Navbar.vue +++ b/frontend/src/components/Navbar.vue @@ -7,6 +7,7 @@