diff --git a/code/services-application/api-service/src/main/java/nu/marginalia/api/ApiService.java b/code/services-application/api-service/src/main/java/nu/marginalia/api/ApiService.java index 5fa8baf2..35d9a7a7 100644 --- a/code/services-application/api-service/src/main/java/nu/marginalia/api/ApiService.java +++ b/code/services-application/api-service/src/main/java/nu/marginalia/api/ApiService.java @@ -98,19 +98,16 @@ public class ApiService extends Service { response.type("application/json"); + // Check if we have a cached response var cachedResponse = responseCache.getResults(license, args[0], request.queryString()); if (cachedResponse.isPresent()) { wmsa_api_cache_hit_count.labels(license.key).inc(); return cachedResponse.get(); } + // When no cached response, do the search and cache the result var result = doSearch(license, args[0], request); responseCache.putResults(license, args[0], request.queryString(), result); - - // We set content type late because in the case of error, we don't want to tell the client - // that the error message is JSON when it is plain text. - - return result; }