Package com.sodius.oslc.core.cache
Class CacheFactory
- java.lang.Object
-
- com.sodius.oslc.core.cache.CacheFactory
-
public abstract class CacheFactory extends Object
A factory to create instances ofCacheBuilder
, used to build aCache
.The default implementation uses a Guava cache, which is only valid within the current JVM and cannot be shared across cluster nodes.
Applications can provide their own Guava implementation, that delegates to a cache that is compatible with clusters. To do so, they must change the
CacheFactory
at initialization time, using the following code:CacheFactory.setInstance(new MyClusterCacheFactory());
As the main use for this cache factory is to delegate to cluster compatible implementations, it requires all cache keys and values to beSerializable
.- Since:
- 1.12.0
- See Also:
Cache
,CacheBuilder
-
-
Constructor Summary
Constructors Constructor Description CacheFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <V extends Serializable>
CacheBuilder<V>builder()
Creates a synchronous cache builder.static CacheFactory
getInstance()
Returns the current cache factory instance.static void
setInstance(CacheFactory cacheFactory)
Replaces the current cache factory with the given one.
-
-
-
Method Detail
-
getInstance
public static CacheFactory getInstance()
Returns the current cache factory instance.Default instance uses a standard Guava cache which is only valid within the current JVM.
- Returns:
- the current instance
- See Also:
setInstance(CacheFactory)
-
setInstance
public static void setInstance(CacheFactory cacheFactory)
Replaces the current cache factory with the given one.- Parameters:
cacheFactory
- the new cache factory
-
builder
public abstract <V extends Serializable> CacheBuilder<V> builder()
Creates a synchronous cache builder.This builder must guarantee that the caches it creates are synchronous, meaning when a cache is updated on a cluster node, it must not release the thread until all cluster nodes are notified of the new value.
- Type Parameters:
V
- the base value type for all caches created by this builder- Returns:
- a cache builder
-
-