Skip to content

Commit 00970d6

Browse files
⚡ perf: Add Redis caching to /v1/domain-breach-summary
1 parent 088809c commit 00970d6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

api/v1/breaches.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,13 @@ async def get_domain_breach_summary(
547547
try:
548548
domain = d.lower().strip()
549549

550-
# Initialize datastores
550+
# Check cache first
551+
cache_key = f"domain-breach-summary:{domain}"
552+
cached_result = get_cached_breaches(cache_key)
553+
if cached_result:
554+
return DomainBreachSummaryResponse(**cached_result)
555+
556+
# Cache miss - query Datastore
551557
ds_xon = datastore.Client()
552558

553559
# Query xon records for domain
@@ -613,6 +619,10 @@ async def get_domain_breach_summary(
613619
]
614620
}
615621

622+
# Cache the response
623+
response_data = {"sendDomains": breaches_dict, "SearchStatus": "Success"}
624+
cache_breaches(cache_key, response_data)
625+
616626
return DomainBreachSummaryResponse(
617627
sendDomains=breaches_dict, SearchStatus="Success"
618628
)

0 commit comments

Comments
 (0)