improved context cache

This commit is contained in:
Luca Frosini 2023-05-10 17:15:10 +02:00
parent f6f2402b07
commit e7e251dac8
2 changed files with 13 additions and 8 deletions

View File

@ -3,8 +3,10 @@ package org.gcube.informationsystem.resourceregistry.api.contexts;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@ -49,11 +51,11 @@ public class ContextCache {
cleanCache(Calendar.getInstance());
}
private void cleanCache(Calendar now) {
protected void cleanCache(Calendar now) {
this.contexts = null;
this.uuidToContext = new HashMap<>();
this.uuidToContextFullName = new HashMap<>();
this.contextFullNameToUUID = new HashMap<>();
this.uuidToContext = new LinkedHashMap<>();
this.uuidToContextFullName = new LinkedHashMap<>();
this.contextFullNameToUUID = new TreeMap<>();
this.creationTime = Calendar.getInstance();
this.creationTime.setTimeInMillis(now.getTimeInMillis());
this.expiringTime = Calendar.getInstance();
@ -78,6 +80,10 @@ public class ContextCache {
cleanCache(now);
}
public ContextCacheRenewal getContextCacheRenewal() {
return contextCacheRenewal;
}
public void setContextCacheRenewal(ContextCacheRenewal contextCacheRenewal) {
if(this.contextCacheRenewal==null) {
this.contextCacheRenewal = contextCacheRenewal;
@ -106,7 +112,7 @@ public class ContextCache {
return contexts;
}
private void setContexts(List<Context> contexts) {
protected void setContexts(List<Context> contexts) {
this.contexts = new ArrayList<>();
for(Context c : contexts) {
@ -144,7 +150,7 @@ public class ContextCache {
}
private String getContextFullName(Context context) {
protected String getContextFullName(Context context) {
StringBuilder stringBuilder = new StringBuilder();
IsParentOf ipo = context.getParent();
if(ipo!=null) {

View File

@ -49,8 +49,7 @@ public class ContextUtility {
return uuids;
}
public static Set<String> getContextFullNameSet(Collection<UUID> uuids) throws Exception {
ContextCache contextCache = ContextCache.getInstance();
public static Set<String> getContextFullNameSet(ContextCache contextCache, Collection<UUID> uuids) throws Exception {
Set<String> contextFullNames = new HashSet<>();
try {
Map<UUID, String> uuidToContextFullNameAssociation = contextCache.getUUIDToContextFullNameAssociation();