minor fixes for the caches
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@140058 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5dfa58909a
commit
ceca8a5497
|
@ -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<String, String> userEmailCache = new CacheImpl<String, String>(1000 * 60 * 30);
|
||||
private static CacheInterface<String, String> userFullnameCache = new CacheImpl<String, String>(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
|
||||
|
|
|
@ -10,14 +10,14 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Costantino Perciante at ISTI-CNR
|
||||
* (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class CacheImpl implements CacheInterface<String, Long> {
|
||||
public class CacheImpl <K, V> implements CacheInterface<K, V> {
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CacheImpl.class);
|
||||
|
||||
/**
|
||||
* The hashmap
|
||||
*/
|
||||
private Map<String, CacheValueBean<Long>> userSpaceMap;
|
||||
private Map<K, CacheValueBean<V>> userSpaceMap;
|
||||
|
||||
/**
|
||||
* Cache entry expires after EXPIRED_AFTER ms
|
||||
|
@ -30,10 +30,10 @@ public class CacheImpl implements CacheInterface<String, Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Long get(String key) {
|
||||
public V get(K key) {
|
||||
|
||||
if(userSpaceMap.containsKey(key)){
|
||||
CacheValueBean<Long> bean = userSpaceMap.get(key);
|
||||
CacheValueBean<V> 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<String, Long> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean insert(String key, Long value) {
|
||||
CacheValueBean<Long> newBean = new CacheValueBean<Long>(value, System.currentTimeMillis());
|
||||
public boolean insert(K key, V obj) {
|
||||
CacheValueBean<V> newBean = new CacheValueBean<V>(obj, System.currentTimeMillis());
|
||||
userSpaceMap.put(key, newBean);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue