Class DistributedCaffeine<K,V>
- java.lang.Object
-
- io.github.oberhoff.distributedcaffeine.DistributedCaffeine<K,V>
-
- Type Parameters:
K
- the key type of the cacheV
- the value type of the cache
public final class DistributedCaffeine<K,V> extends Object
Distributed Caffeine is aCaffeine
-based distributed cache using MongoDB change streams for near real-time synchronization between multiple cache instances, especially across different machines.Cache instances can be configured and constructed using a builder returned by
newBuilder(MongoCollection)
. A cache instance can be of typeDistributedCache
(extendsCache
) or of typeDistributedLoadingCache
(extendsLoadingCache
).Attention: To ensure the integrity of distributed synchronization between cache instances, the following minor restrictions apply:
- Reference-based eviction using Caffeine's weak or soft references for keys or values is not supported. Even for the use of Caffeine (stand-alone), it is advised to use the more predictable size- or time-based eviction instead.
- Author:
- Andreas Oberhoff
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DistributedCaffeine.Builder<K,V>
Builder for configuring and constructing cache instances of typeDistributedCache
(extendsCache
) or of typeDistributedLoadingCache
(extendsLoadingCache
).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
DistributedCaffeine.Builder<K,V>newBuilder(com.mongodb.client.MongoCollection<org.bson.Document> mongoCollection)
Returns a new builder for configuring and constructing cache instances.
-
-
-
Method Detail
-
newBuilder
public static <K,V> DistributedCaffeine.Builder<K,V> newBuilder(com.mongodb.client.MongoCollection<org.bson.Document> mongoCollection)
Returns a new builder for configuring and constructing cache instances. For example, the builder can be finalized withDistributedCaffeine.Builder.build()
to construct a cache instance of typeDistributedCache
(extendsCache
) or withDistributedCaffeine.Builder.build(CacheLoader)
to construct a loading cache instance of typeDistributedLoadingCache
(extendsLoadingCache
).Note: A call to this method must use additional generic type parameters for key and value directly before the method name like in the following example:
DistributedCache<Key, Value> distributedCache = DistributedCaffeine.<Key, Value>newBuilder(mongoCollection) ... .build();
- Type Parameters:
K
- the key type of the cacheV
- the value type of the cache- Parameters:
mongoCollection
- the MongoDB collection used for distributed synchronization between cache instances- Returns:
- builder for configuring and constructing cache instances
-
-