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.

Release CacheLoaders.asyncReload

See original GitHub issue

Original issue created by electrum on 2013-12-30 at 09:30 PM


The documentation for CacheLoader.refreshAfterWrite() recommends overriding reload() with an asynchronous version. We use the following in many places and think it could be a good addition to Guava:

public abstract class BackgroundCacheLoader<K, V>         extends CacheLoader<K, V> {     private final ListeningExecutorService executor;

protected BackgroundCacheLoader(ListeningExecutorService executor)
{
    this.executor = checkNotNull(executor, "executor is null");
}

@Override
public final ListenableFuture<V> reload(final K key, V oldValue)
        throws Exception
{
    return executor.submit(new Callable<V>()
    {
        @Override
        public V call()
                throws Exception
        {
            return load(key);
        }
    });
}

}

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
noahlzcommented, Oct 31, 2016

You should totally update the Caches Explained wiki to mention this API! 💯

1reaction
Davetroncommented, Dec 1, 2016

Any examples on how to use asyncReloading?

I’m using CacheBuilder with Spring cache. Presumably it’s automagically creating a default LoadingCache somewhere along the way to the @Cacheable but it’d be nice to configure a cache that does async reloading without having to override CacheLoader.reload()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guava cache asynchronous reload - Stack Overflow
@BenManes - I am unable to remove load method from my original implementation as this method is abstract in CacheLoader. Additionally I am...
Read more >
CacheLoader (Guava: Google Core Libraries for Java 22.0 API)
Returns a CacheLoader which wraps loader , executing calls to reload(K, V) using executor . This method is useful only when loader.reload has...
Read more >
CacheLoader asyncReloading - Google Groups
asyncReloading, to be used for asynchronous loading/refreshing for cache ... CacheLoader.reload gets called when there's a preexisting entry for the key ...
Read more >
CacheLoader (caffeine 2.3.0 API) - javadoc.io
Asynchronously computes or retrieves a replacement value corresponding to an already-cached key . If the replacement value is not found then the mapping...
Read more >
com.google.common.cache.CacheLoader.asyncReloading ...
MINUTES) // prevent from hanging on to memory forever .build(asyncReloading(new GrokReloader(true), daemonExecutor)); // trigger initial loading reload(); ...
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