Skip to content

Commit 62b5b6d

Browse files
fix: update caching logic and response headers for catalog retrieval
1 parent 7e74aa7 commit 62b5b6d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

app/api/endpoints/catalogs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ async def get_catalog(type: str, id: str, response: Response, token: str):
6464
cleaned = [m for m in cleaned if m is not None]
6565

6666
data = {"metas": cleaned}
67-
await redis_service.set(catalog_key, json.dumps(data), settings.CATALOG_CACHE_TTL)
67+
# if catalog data is not empty, set the cache
68+
if cleaned:
69+
await redis_service.set(catalog_key, json.dumps(data), settings.CATALOG_CACHE_TTL)
6870
return data
6971

7072
except HTTPException:

app/services/recommendation/catalog_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async def get_catalog(
113113
logger.info(f"Returning {len(recommendations)} items for {content_type}")
114114

115115
# Prepare response headers
116-
headers = {"Cache-Control": "public, max-age=21600"} # 6 hours
116+
headers = {"Cache-Control": f"public, max-age={settings.CATALOG_CACHE_TTL}"}
117117

118118
return recommendations, headers
119119

0 commit comments

Comments
 (0)