com.github.blemale.scaffeine.CacheLoaderAdapter Maven / Gradle / Ivy
package com.github.blemale.scaffeine;
import com.github.benmanes.caffeine.cache.CacheLoader;
import scala.Function1;
import scala.Function2;
import scala.Option;
import javax.annotation.Nonnull;
class CacheLoaderAdapter implements CacheLoader{
private final Function1 loader;
private final Option> reloadLoader;
CacheLoaderAdapter(Function1 loader, Option> reloadLoader) {
this.loader = loader;
this.reloadLoader = reloadLoader;
}
@Override
public V load(@Nonnull K key) {
return loader.apply(key);
}
@Override
public V reload(@Nonnull K key, @Nonnull V oldValue) throws Exception {
if (reloadLoader.isEmpty()) {
return CacheLoader.super.reload(key, oldValue);
} else {
return reloadLoader.get().apply(key, oldValue);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy