diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java index 9a0309f..544f896 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/HelperMethods.java @@ -58,8 +58,8 @@ public abstract class HelperMethods { private static final String PATH_SEPARATOR = "/"; // caches - private static CacheInterface userEmailCache = new CacheImpl(1000 * 60 * 30); - private static CacheInterface userFullnameCache = new CacheImpl(1000 * 60 * 30); + private static CacheInterface userEmailCache = new CacheImpl(1000 * 60 * 30); + private static CacheInterface userFullnameCache = new CacheImpl(1000 * 60 * 30); /** * Convert a group name to its id on ckan @@ -132,7 +132,6 @@ public abstract class HelperMethods { * @return * @throws Exception */ - @SuppressWarnings("unchecked") public static String getUserEmail(String context, String token){ // check in cache @@ -156,7 +155,6 @@ public abstract class HelperMethods { * @return * @throws Exception */ - @SuppressWarnings("unchecked") public static String getUserFullname(String context, String token){ // check in cache diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java index 4e66e04..f5054a1 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/cache/CacheImpl.java @@ -10,14 +10,14 @@ import org.slf4j.LoggerFactory; * @author Costantino Perciante at ISTI-CNR * (costantino.perciante@isti.cnr.it) */ -public class CacheImpl implements CacheInterface { +public class CacheImpl implements CacheInterface { private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CacheImpl.class); /** * The hashmap */ - private Map> userSpaceMap; + private Map> userSpaceMap; /** * Cache entry expires after EXPIRED_AFTER ms @@ -30,10 +30,10 @@ public class CacheImpl implements CacheInterface { } @Override - public Long get(String key) { + public V get(K key) { if(userSpaceMap.containsKey(key)){ - CacheValueBean bean = userSpaceMap.get(key); + CacheValueBean bean = userSpaceMap.get(key); if(CacheUtilities.expired(bean.getTTL(), ttl)){ userSpaceMap.remove(key); logger.debug("Amount of space in the infrastructure used expired for key " + key + ", returning null"); @@ -45,8 +45,8 @@ public class CacheImpl implements CacheInterface { } @Override - public boolean insert(String key, Long value) { - CacheValueBean newBean = new CacheValueBean(value, System.currentTimeMillis()); + public boolean insert(K key, V obj) { + CacheValueBean newBean = new CacheValueBean(obj, System.currentTimeMillis()); userSpaceMap.put(key, newBean); return true; } diff --git a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java index 82284a3..143eae2 100644 --- a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java +++ b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/JTests.java @@ -42,6 +42,7 @@ import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Status; import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; +import org.junit.Test; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; @@ -516,4 +517,15 @@ public class JTests { } + + //@Test + public void testCaches(){ + + String context = "/gcube/devNext/NextNext"; + String token = ""; + for (int i = 0; i < 1000; i++) { + logger.debug(HelperMethods.getUserEmail(context, token)); + } + + } }