Class CacheFactory


  • public abstract class CacheFactory
    extends Object
    A factory to create instances of CacheBuilder, used to build a Cache.

    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 be Serializable.
    Since:
    1.12.0
    See Also:
    Cache, CacheBuilder
    • Constructor Detail

      • CacheFactory

        public CacheFactory()
    • 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 SerializableCacheBuilder<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