Release CacheLoaders.asyncReload
See original GitHub issueOriginal 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:
- Created 9 years ago
- Comments:6 (1 by maintainers)
Top 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 >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
You should totally update the Caches Explained wiki to mention this API! 💯
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()