Add Java 8 / lambda friendly helper for CacheLoader
See original GitHub issueAlmost every usage of CacheLoader
only needs to implement load()
, so being able to do that with a lambda would be helpful. Something like this:
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;
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:14 (10 by maintainers)
Top Results From Across the Web
Using Java 8 Lambdas with Google Guava Caches
With Guava, you can define a simple in-memory cache with.
Read more >Everything about Java 8 - TechEmpower Blog
An abstract class, even if it declares only one abstract method, cannot be instantiated with a lambda. Two examples of classes with one...
Read more >Guava and JDK 8 / Java 8 - Google Groups
The good news for users is that lambdas should work with both the Guava (for Java 7) and Java 8 flavors, so you...
Read more >How to pass more than one parameter in google Cache ...
The loader, a Callable , is a "capturing lambda" which means that it has access to parameters in the surrounding scope. The drawback...
Read more >In-Memory Caching - Quinbay
Caching isn't an architecture, it's just about optimisation. It provides fast response time, enabling effortless performance improvements in many use cases.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note there already is this for a bare
Function
: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/cache/CacheLoader.html#from-com.google.common.base.Function-Well, perhaps consider
Caffeine.newBuilder().build(key -> ...)
? https://github.com/ben-manes/caffeine