A com.twitter.cache.FutureCache backed by a java.util.concurrent.ConcurrentMap
FutureCache is used to represent an in-memory, in-process, asynchronous cache.
FutureCache is used to represent an in-memory, in-process, asynchronous cache.
Every cache operation is atomic.
Any correct implementation should make sure that you evict failed results, and don't interrupt the underlying request that has been fired off. EvictingCache and Future#interrupting are useful tools for building correct FutureCaches. A reference implementation for caching the results of an asynchronous function can be found at FutureCache$.default.
A proxy for FutureCaches, useful for wrap-but-modify.
The FutureCache object provides the public interface for constructing FutureCaches.
The FutureCache object provides the public interface for constructing FutureCaches. Once you've constructed a basic FutureCache, you should almost always wrap it with default. Normal usage looks like:
val fn: K => Future[V] val map = (new java.util.concurrent.ConcurrentHashMap[K, V]()).asScala val cachedFn: K => Future[V] = FutureCache.default(fn, FutureCache.fromMap(map))
We typically recommend that you use Guava Caches. There's an API that makes it easy to use Guava caches, and can be found in the util-collection lib. The object is called com.twitter.cache.guava.Guava$.
A com.twitter.cache.FutureCache backed by a java.util.concurrent.ConcurrentMap
Any correct implementation should make sure that you evict failed results, and don't interrupt the underlying request that has been fired off. EvictingCache and Future#interrupting are useful tools for building correct FutureCaches. A reference implementation for caching the results of an asynchronous function with a ConcurrentMap can be found at FutureCache$.fromMap.