com.github.phantomthief.util.GlobalCache Maven / Gradle / Ivy
/**
*
*/
package com.github.phantomthief.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
/**
*
* @author w.vela
*/
public final class GlobalCache implements IMultiDataAccess {
private final Cache cache = CacheBuilder.newBuilder().weakKeys().weakValues().build();
@Override
public Map get(Collection keys) {
Map result = new HashMap<>();
for (K key : keys) {
V value = cache.getIfPresent(key);
if (value != null) {
result.put(key, value);
}
}
return result;
}
@Override
public void set(Map dataMap) {
cache.putAll(dataMap);
};
public void remove(K key) {
cache.invalidate(key);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy