question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Java 8 / lambda friendly helper for CacheLoader

See original GitHub issue

Almost 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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ben-manescommented, Jan 13, 2018

Well, perhaps consider Caffeine.newBuilder().build(key -> ...)? https://github.com/ben-manes/caffeine

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found