Commit 377e2732 authored by Matija Obreza's avatar Matija Obreza
Browse files

Caching: Caching with HZ requires serializable filters

parent e081cc41
......@@ -28,10 +28,8 @@ import java.util.UUID;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import com.querydsl.core.types.Predicate;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.auditlog.service.AuditTrailService;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.QDataset;
......@@ -53,7 +51,6 @@ import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.QCrop;
import org.genesys2.server.model.impl.QSubset;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.persistence.AccessionIdRepository;
......@@ -73,6 +70,7 @@ import org.genesys2.spring.TransactionHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
......@@ -250,7 +248,7 @@ public class AccessionServiceImpl implements AccessionService {
auditLog.auditAccessionId = auditService.auditLogs(accession.getAccessionId());
auditLog.auditAccessionCollect = auditService.auditLogs(accession.getAccessionId().getColl());
// TODO Update the UI
//auditLog.auditAccessionGeo = auditService.auditLogs(accession.getAccessionId().getGeo());
//auditLog.auditAccessionGeo = auditService.auditLogs(accession.getAccessionId().getGeo());
return auditLog;
}
......@@ -259,7 +257,7 @@ public class AccessionServiceImpl implements AccessionService {
public Map<UUID, AccessionIdentifier3> toUUID(List<? extends AccessionIdentifier3> identifiers) {
if (CollectionUtils.isEmpty(identifiers)) {
return Collections.emptyMap();
return Collections.emptyMap();
}
Map<UUID, AccessionIdentifier3> res = new HashMap<>();
......@@ -279,14 +277,14 @@ public class AccessionServiceImpl implements AccessionService {
return res;
}
@Override
public List<Accession> forUuids(Set<UUID> uuids) {
@Override
public List<Accession> forUuids(Set<UUID> uuids) {
if (CollectionUtils.isEmpty(uuids)) {
return Collections.emptyList();
}
if (CollectionUtils.isEmpty(uuids)) {
return Collections.emptyList();
}
List<UUID> uuidList = new ArrayList<>(uuids);
List<UUID> uuidList = new ArrayList<>(uuids);
List<Accession> accessions = new ArrayList<>(uuids.size());
for (int fromIndex = 0; fromIndex < uuids.size(); fromIndex+= LOAD_CHUNK_SIZE){
......@@ -301,6 +299,7 @@ public class AccessionServiceImpl implements AccessionService {
@Override
// @Cacheable(value = "accessionCount", keyGenerator = "shortFilterKeyGenerator")
@Cacheable(cacheNames = "apiResponses.accession.count", unless = "#result < 10000")
public long countAccessions(AccessionFilter filter) throws SearchException {
long total;
......@@ -574,6 +573,7 @@ public class AccessionServiceImpl implements AccessionService {
}
@Override
@Cacheable(cacheNames = "apiResponses.accession.suggestions", sync = true)
public Map<String, ElasticsearchService.TermResult> getSuggestions(AccessionFilter filter) throws SearchException, IOException {
if (elasticsearchService == null)
......@@ -633,6 +633,7 @@ public class AccessionServiceImpl implements AccessionService {
}
@Override
@Cacheable(cacheNames = "apiResponses.accession.geobounds", sync = true)
public Number[][] getGeoBounds(AccessionFilter filter) {
if (filter.isFulltextQuery()) {
......
......@@ -351,13 +351,13 @@ public abstract class HazelcastConfig {
final MapConfig apiResponseConfig = new MapConfig();
apiResponseConfig.setName("apiResponses.*");
apiResponseConfig.setTimeToLiveSeconds(60 * 2); // 2min
apiResponseConfig.setMaxIdleSeconds(30);
apiResponseConfig.setTimeToLiveSeconds(60 * 5); // 5min
apiResponseConfig.setMaxIdleSeconds(60 * 3); // 3min
{
final EvictionConfig evictionConfig = new EvictionConfig();
evictionConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
evictionConfig.setEvictionPolicy(EvictionPolicy.LFU);
// evictionConfig.setSize(50);
// evictionConfig.setMaxSizePolicy(MaxSizePolicy.PER_NODE);
evictionConfig.setSize(50); // cache up to 50 entries
apiResponseConfig.setEvictionConfig(evictionConfig);
}
cfg.addMapConfig(apiResponseConfig);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment