use of com.github.benmanes.caffeine.cache.LoadingCache in project LanternServer by LanternPowered.
the class LanternContextCalculator method buildAddressCache.
private LoadingCache<RemoteSource, Set<Context>> buildAddressCache(final String contextKey, final Function<RemoteSource, InetAddress> function) {
return Caffeine.newBuilder().weakKeys().build(key -> {
final ImmutableSet.Builder<Context> builder = ImmutableSet.builder();
final InetAddress address = checkNotNull(function.apply(key), "address");
builder.add(new Context(contextKey, address.getHostAddress()));
for (String set : Maps.filterValues(Lantern.getGame().getGlobalConfig().getIpSets(), input -> input.test(address)).keySet()) {
builder.add(new Context(contextKey, set));
}
return builder.build();
});
}
Aggregations