Skip to content

Instantly share code, notes, and snippets.

@electrum
Created April 2, 2016 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electrum/f77aa240ed3cdb70bcd5a1296b00642c to your computer and use it in GitHub Desktop.
Save electrum/f77aa240ed3cdb70bcd5a1296b00642c to your computer and use it in GitHub Desktop.
import com.google.common.cache.CacheLoader;
public final class CacheLoaderUtil
{
private CacheLoaderUtil() {}
public static <K, V> CacheLoader<K, V> cacheLoader(LoaderFunction<K, V> loader)
{
return new CacheLoader<K, V>()
{
@Override
public V load(K key)
throws Exception
{
return loader.load(key);
}
};
}
public interface LoaderFunction<K, V>
{
V load(K key)
throws Exception;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment