(api-service) Mq endpoint for flushing caches

This commit is contained in:
Viktor Lofgren 2023-08-05 14:42:16 +02:00
parent 00eb8b90dc
commit 08eed17e66
3 changed files with 17 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import nu.marginalia.model.gson.GsonFactory;
import nu.marginalia.search.client.SearchClient;
import nu.marginalia.search.client.model.ApiSearchResults;
import nu.marginalia.service.server.*;
import nu.marginalia.service.server.mq.MqNotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
@ -58,6 +59,14 @@ public class ApiService extends Service {
Spark.get("/public/api/:key/search/*", this::search, gson::toJson);
}
@MqNotification(endpoint = "FLUSH_CACHES")
public void flushCaches(String unusedArg) {
logger.info("Flushing caches");
responseCache.flush();
licenseService.flushCache();
}
private Object search(Request request, Response response) {
String[] args = request.splat();

View File

@ -8,7 +8,6 @@ import nu.marginalia.api.model.ApiLicense;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.Request;
import spark.Spark;
import java.util.concurrent.ConcurrentHashMap;
@ -57,4 +56,8 @@ public class LicenseService {
throw new IllegalStateException("This is unreachable");
}
public void flushCache() {
licenseCache.clear();
}
}

View File

@ -40,6 +40,10 @@ public class ResponseCache {
return license.getKey() + ":" + queryString + ":" + queryParams;
}
public void flush() {
cache.invalidateAll();
}
public void cleanUp() {
cache.cleanUp();
}