Class CacheManagerBuilder<T extends org.ehcache.CacheManager>

java.lang.Object
org.ehcache.config.builders.CacheManagerBuilder<T>
All Implemented Interfaces:
org.ehcache.config.Builder<T>

public class CacheManagerBuilder<T extends org.ehcache.CacheManager> extends Object implements org.ehcache.config.Builder<T>
The CacheManagerBuilder enables building cache managers using a fluent style.

As with all Ehcache builders, all instances are immutable and calling any method on the builder will return a new instance without modifying the one on which the method was called. This enables the sharing of builder instances without any risk of seeing them modified by code elsewhere.

  • Method Details

    • build

      public T build(boolean init)
      Builds a CacheManager or a subtype of it and initializes it if requested.
      Parameters:
      init - whether the returned CacheManager is to be initialized or not
      Returns:
      a CacheManager or a subtype of it
    • build

      public T build()
      Builds a CacheManager or a subtype of it uninitialized.
      Specified by:
      build in interface org.ehcache.config.Builder<T extends org.ehcache.CacheManager>
      Returns:
      a CacheManager or a subtype of it uninitialized
    • newCacheManager

      public static org.ehcache.CacheManager newCacheManager(org.ehcache.config.Configuration configuration)
      Creates a new CacheManager based on the provided configuration. The returned CacheManager is uninitialized.
      Parameters:
      configuration - the configuration to use
      Returns:
      a CacheManager
    • withCache

      public <K, V> CacheManagerBuilder<T> withCache(String alias, org.ehcache.config.CacheConfiguration<K,V> configuration)
      Adds a CacheConfiguration linked to the specified alias to the returned builder.
      Type Parameters:
      K - the cache key type
      V - the cache value type
      Parameters:
      alias - the cache alias
      configuration - the CacheConfiguration
      Returns:
      a new builder with the added cache configuration
      See Also:
    • withCache

      public <K, V> CacheManagerBuilder<T> withCache(String alias, org.ehcache.config.Builder<? extends org.ehcache.config.CacheConfiguration<K,V>> configurationBuilder)
      Convenience method to add a CacheConfiguration linked to the specified alias to the returned builder by building it from the provided Builder.
      Type Parameters:
      K - the cache key type
      V - the cache value type
      Parameters:
      alias - the cache alias
      configurationBuilder - the Builder to get CacheConfiguration from
      Returns:
      a new builder with the added cache configuration
      See Also:
    • with

      public <N extends T> CacheManagerBuilder<N> with(CacheManagerConfiguration<N> cfg)
      Specializes the returned CacheManager subtype through a specific CacheManagerConfiguration which will optionally add configurations to the returned builder.
      Type Parameters:
      N - the subtype of CacheManager
      Parameters:
      cfg - the CacheManagerConfiguration to use
      Returns:
      a new builder ready to build a more specific subtype of cache manager
      See Also:
    • with

      public <N extends T> CacheManagerBuilder<N> with(org.ehcache.config.Builder<? extends CacheManagerConfiguration<N>> cfgBuilder)
      Convenience method to specialize the returned CacheManager subtype through a CacheManagerConfiguration built using the provided Builder.
      Parameters:
      cfgBuilder - the Builder to get the CacheManagerConfiguration from
      Returns:
      a new builder ready to build a more specific subtype of cache manager
      See Also:
    • using

      public CacheManagerBuilder<T> using(org.ehcache.spi.service.Service service)
      Adds a Service instance to the returned builder.

      The service instance will be used by the constructed CacheManager.

      Parameters:
      service - the Service to add
      Returns:
      a new builder with the added service
    • withCopier

      public <C> CacheManagerBuilder<T> withCopier(Class<C> clazz, Class<? extends org.ehcache.spi.copy.Copier<C>> copier)
      Adds a default Copier for the specified type to the returned builder.
      Type Parameters:
      C - the type which can be copied
      Parameters:
      clazz - the Class for which the copier is
      copier - the Copier instance
      Returns:
      a new builder with the added default copier
    • withSerializer

      public <C> CacheManagerBuilder<T> withSerializer(Class<C> clazz, Class<? extends org.ehcache.spi.serialization.Serializer<C>> serializer)
      Adds a default Serializer for the specified type to the returned builder.
      Type Parameters:
      C - the type which can be serialized
      Parameters:
      clazz - the Class for which the serializer is
      serializer - the Serializer instance
      Returns:
      a new builder with the added default serializer
    • withDefaultSizeOfMaxObjectGraph

      @Deprecated public CacheManagerBuilder<T> withDefaultSizeOfMaxObjectGraph(long size)
      Deprecated.
      Adds a default SizeOfEngine configuration, that limits the max object graph to size, to the returned builder.
      Parameters:
      size - the max object graph size
      Returns:
      a new builder with the added configuration
    • withDefaultSizeOfMaxObjectSize

      @Deprecated public CacheManagerBuilder<T> withDefaultSizeOfMaxObjectSize(long size, org.ehcache.config.units.MemoryUnit unit)
      Deprecated.
      Adds a default SizeOfEngine configuration, that limits the max object size, to the returned builder.
      Parameters:
      size - the max object size
      unit - the max object size unit
      Returns:
      a new builder with the added configuration
    • withDefaultWriteBehindThreadPool

      public CacheManagerBuilder<T> withDefaultWriteBehindThreadPool(String threadPoolAlias)
      Adds a WriteBehindProviderConfiguration, that specifies the thread pool to use, to the returned builder.
      Parameters:
      threadPoolAlias - the thread pool alias
      Returns:
      a new builder with the added configuration
      See Also:
    • withDefaultDiskStoreThreadPool

      public CacheManagerBuilder<T> withDefaultDiskStoreThreadPool(String threadPoolAlias)
      Adds a OffHeapDiskStoreProviderConfiguration, that specifies the thread pool to use, to the returned builder.
      Parameters:
      threadPoolAlias - the thread pool alias
      Returns:
      a new builder with the added configuration
      See Also:
    • withDefaultEventListenersThreadPool

      public CacheManagerBuilder<T> withDefaultEventListenersThreadPool(String threadPoolAlias)
      Adds a CacheEventDispatcherFactoryConfiguration, that specifies the thread pool to use, to the returned builder.
      Parameters:
      threadPoolAlias - the thread pool alias
      Returns:
      a new builder with the added configuration
      See Also:
    • using

      public CacheManagerBuilder<T> using(org.ehcache.spi.service.ServiceCreationConfiguration<?,?> serviceConfiguration)
      Adds a ServiceCreationConfiguration to the returned builder.

      These configurations are used to load services and configure them at creation time. This method will remove any existing configuration incompatible with the given configuration, before adding the new configuration.

      Parameters:
      serviceConfiguration - the ServiceCreationConfiguration to use
      Returns:
      a new builder with the added configuration
      See Also:
      • FluentConfigurationBuilder.withService(ServiceCreationConfiguration)
    • replacing

      @Deprecated public CacheManagerBuilder<T> replacing(org.ehcache.spi.service.ServiceCreationConfiguration<?,?> overwriteServiceConfiguration)
      Deprecated.
      in favor of using(ServiceCreationConfiguration) whose refined contract matches this one
      Replaces an existing ServiceCreationConfiguration of the same type on the returned builder.

      Duplicate service creation configuration will cause a cache manager to fail to initialize.

      Parameters:
      overwriteServiceConfiguration - the new ServiceCreationConfiguration to use
      Returns:
      a new builder with the replaced configuration
    • withClassLoader

      public CacheManagerBuilder<T> withClassLoader(ClassLoader classLoader)
      Adds a ClassLoader, to use for non Ehcache types, to the returned builder
      Parameters:
      classLoader - the class loader to use
      Returns:
      a new builder with the added class loader
    • newCacheManagerBuilder

      public static CacheManagerBuilder<org.ehcache.CacheManager> newCacheManagerBuilder()
      Creates a new CacheManagerBuilder
      Returns:
      the cache manager builder
    • persistence

      public static CacheManagerConfiguration<org.ehcache.PersistentCacheManager> persistence(String rootDirectory)
      Convenience method to get a CacheManagerConfiguration for a PersistentCacheManager stored on disk. The actual level of persistence is configured on the disk resource pool per cache.
      Parameters:
      rootDirectory - the root directory to use for disk storage
      Returns:
      a CacheManagerConfiguration
      See Also:
    • persistence

      public static CacheManagerConfiguration<org.ehcache.PersistentCacheManager> persistence(File rootDirectory)
      Convenience method to get a CacheManagerConfiguration for a PersistentCacheManager stored on disk. The actual level of persistence is configured on the disk resource pool per cache.
      Parameters:
      rootDirectory - the root directory to use for disk storage
      Returns:
      a CacheManagerConfiguration
      See Also:
    • sharedResources

      public CacheManagerBuilder<T> sharedResources(org.ehcache.config.Builder<? extends org.ehcache.config.ResourcePools> sharedResourcePoolsBuilder)
      Defines a ResourcePools, containing one or more ResourcePools that configured caches can reference, such that their caching requirements will be managed via the shared pool.
      Parameters:
      sharedResourcePoolsBuilder - the resources to share
      Returns:
      a new builder with the added configuration