Fix and improve remote fetcher caching
This commit is contained in:
parent
6ce7fec059
commit
e165259c81
|
@ -0,0 +1,22 @@
|
|||
package eu.eudat.cache;
|
||||
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ExternalUrlsKeyGenerator implements KeyGenerator {
|
||||
@Override
|
||||
public Object generate(Object o, Method method, Object... params) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(o.getClass().getSimpleName()).append("_");
|
||||
stringBuffer.append(method.getName()).append("_");
|
||||
for (Object param: params) {
|
||||
if (param instanceof ExternalUrlCriteria) {
|
||||
ExternalUrlCriteria externalUrlCriteria = (ExternalUrlCriteria) param;
|
||||
stringBuffer.append(externalUrlCriteria);
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.caffeine.CaffeineCache;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -47,4 +48,9 @@ public class ResponsesCache {
|
|||
return simpleCacheManager;
|
||||
}
|
||||
|
||||
@Bean(name = "externalUrlsKeyGenerator")
|
||||
private KeyGenerator externalUrlsKeyGenerator() {
|
||||
return new ExternalUrlsKeyGenerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,4 +58,16 @@ public class ExternalUrlCriteria {
|
|||
|
||||
public ExternalUrlCriteria() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" +
|
||||
"like='" + like + '\'' +
|
||||
", page='" + page + '\'' +
|
||||
", pageSize='" + pageSize + '\'' +
|
||||
", funderId='" + funderId + '\'' +
|
||||
", path='" + path + '\'' +
|
||||
", host='" + host + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class RemoteFetcher {
|
|||
this.configLoader = configLoader;
|
||||
}
|
||||
|
||||
@Cacheable("repositories")
|
||||
@Cacheable(value = "repositories", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getRepositories(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs =
|
||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRepositories().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||
|
@ -50,28 +50,28 @@ public class RemoteFetcher {
|
|||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("grants")
|
||||
@Cacheable(value = "grants", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getGrants(ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getGrants().getUrls();
|
||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getGrants().getFetchMode();
|
||||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("projects")
|
||||
@Cacheable(value = "projects", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getProjects(ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getProjects().getUrls();
|
||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getProjects().getFetchMode();
|
||||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("funders")
|
||||
@Cacheable(value = "funders", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getFunders(ExternalUrlCriteria externalUrlCriteria) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs = configLoader.getExternalUrls().getFunders().getUrls();
|
||||
FetchStrategy fetchStrategy = configLoader.getExternalUrls().getFunders().getFetchMode();
|
||||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("organisations")
|
||||
@Cacheable(value = "organisations", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getOrganisations(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs =
|
||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getOrganisations().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||
|
@ -80,7 +80,7 @@ public class RemoteFetcher {
|
|||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("registries")
|
||||
@Cacheable(value = "registries", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getRegistries(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs =
|
||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getRegistries().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||
|
@ -89,7 +89,7 @@ public class RemoteFetcher {
|
|||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("services")
|
||||
@Cacheable(value = "services", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getServices(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs =
|
||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getServices().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||
|
@ -98,7 +98,7 @@ public class RemoteFetcher {
|
|||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("researchers")
|
||||
@Cacheable(value = "researchers", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getResearchers(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs =
|
||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getResearchers().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||
|
@ -116,7 +116,7 @@ public class RemoteFetcher {
|
|||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}*/
|
||||
|
||||
@Cacheable("externalDatasets")
|
||||
@Cacheable(value = "externalDatasets", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getDatasets(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs =
|
||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getDatasets().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||
|
@ -125,7 +125,7 @@ public class RemoteFetcher {
|
|||
return getAll(urlConfigs, fetchStrategy, externalUrlCriteria);
|
||||
}
|
||||
|
||||
@Cacheable("licenses")
|
||||
@Cacheable(value = "licenses", keyGenerator = "externalUrlsKeyGenerator")
|
||||
public List<Map<String, String>> getlicenses(ExternalUrlCriteria externalUrlCriteria, String key) throws NoURLFound, HugeResultSet {
|
||||
List<UrlConfiguration> urlConfigs =
|
||||
key != null && !key.isEmpty() ? configLoader.getExternalUrls().getLicenses().getUrls().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList())
|
||||
|
|
Loading…
Reference in New Issue