Class CacheConfigurationBuilder<K,V>

java.lang.Object
org.ehcache.config.builders.CacheConfigurationBuilder<K,V>
All Implemented Interfaces:
org.ehcache.config.Builder<org.ehcache.config.CacheConfiguration<K,V>>, org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>

public class CacheConfigurationBuilder<K,V> extends Object implements org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
The CacheConfigurationBuilder enables building CacheConfigurations 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

    • newCacheConfigurationBuilder

      public static <K, V> CacheConfigurationBuilder<K,V> newCacheConfigurationBuilder(Class<K> keyType, Class<V> valueType, org.ehcache.config.ResourcePools resourcePools)
      Creates a new instance ready to produce a CacheConfiguration with key type <K> and with value type <V> and which will use the configured resources.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyType - the key type
      valueType - the value type
      resourcePools - the resources to use
      Returns:
      a CacheConfigurationBuilder
    • newCacheConfigurationBuilder

      public static <K, V> CacheConfigurationBuilder<K,V> newCacheConfigurationBuilder(Class<K> keyType, Class<V> valueType, org.ehcache.config.Builder<? extends org.ehcache.config.ResourcePools> resourcePoolsBuilder)
      Creates a new instance ready to produce a CacheConfiguration with key type <K> and with value type <V> and which will use the configured resources, passed as a ResourcePoolsBuilder.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyType - the key type
      valueType - the value type
      resourcePoolsBuilder - the resources to use, as a builder
      Returns:
      a CacheConfigurationBuilder
    • newCacheConfigurationBuilder

      public static <K, V> CacheConfigurationBuilder<K,V> newCacheConfigurationBuilder(org.ehcache.config.CacheConfiguration<K,V> configuration)
      Creates a new instance ready to produce a CacheConfiguration functionally equivalent to the supplied configuration.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      configuration - seed configuration
      Returns:
      a CacheConfigurationBuilder
    • add

      @Deprecated public CacheConfigurationBuilder<K,V> add(org.ehcache.spi.service.ServiceConfiguration<?,?> configuration)
      Deprecated.
      Adds a ServiceConfiguration to the returned builder.
      Parameters:
      configuration - the service configuration to add
      Returns:
      a new builder with the added service configuration
    • add

      @Deprecated public CacheConfigurationBuilder<K,V> add(org.ehcache.config.Builder<? extends org.ehcache.spi.service.ServiceConfiguration<?,?>> configurationBuilder)
      Deprecated.
      in favor of FluentCacheConfigurationBuilder.withService(Builder)
      Convenience method to add a ServiceConfiguration that is produced by a Builder.
      Parameters:
      configurationBuilder - the service configuration to add, Builder.build() will be called on it
      Returns:
      a new builder with the added service configuration
      See Also:
    • getServices

      public <C extends org.ehcache.spi.service.ServiceConfiguration<?, ?>> Collection<C> getServices(Class<C> configurationType) throws IllegalArgumentException
      Specified by:
      getServices in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
      Throws:
      IllegalArgumentException
    • withService

      public CacheConfigurationBuilder<K,V> withService(org.ehcache.spi.service.ServiceConfiguration<?,?> config)
      Specified by:
      withService in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withoutServices

      public CacheConfigurationBuilder<K,V> withoutServices(Class<? extends org.ehcache.spi.service.ServiceConfiguration<?,?>> clazz)
      Specified by:
      withoutServices in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withoutServices

      public <C extends org.ehcache.spi.service.ServiceConfiguration<?, ?>> CacheConfigurationBuilder<K,V> withoutServices(Class<C> clazz, Predicate<? super C> predicate)
      Specified by:
      withoutServices in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • updateServices

      public <R, C extends org.ehcache.spi.service.ServiceConfiguration<?, R>> CacheConfigurationBuilder<K,V> updateServices(Class<C> clazz, UnaryOperator<R> update)
      Specified by:
      updateServices in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withEvictionAdvisor

      public CacheConfigurationBuilder<K,V> withEvictionAdvisor(org.ehcache.config.EvictionAdvisor<? super K,? super V> evictionAdvisor)
      Specified by:
      withEvictionAdvisor in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • remove

      @Deprecated public CacheConfigurationBuilder<K,V> remove(org.ehcache.spi.service.ServiceConfiguration<?,?> configuration)
      Removes a ServiceConfiguration from the returned builder.
      Parameters:
      configuration - the service configuration to remove
      Returns:
      a new builder without the specified configuration
    • clearAllServiceConfig

      @Deprecated public CacheConfigurationBuilder<K,V> clearAllServiceConfig()
      Clears all ServiceConfigurations from the returned builder.
      Returns:
      a new builder with no service configurations left
    • getExistingServiceConfiguration

      @Deprecated public <T extends org.ehcache.spi.service.ServiceConfiguration<?, ?>> T getExistingServiceConfiguration(Class<T> clazz)
      Deprecated.
      in favor of FluentCacheConfigurationBuilder.getService(Class)
      Returns the first ServiceConfiguration with type matching the class passed in.
      Type Parameters:
      T - the type of the service configuration
      Parameters:
      clazz - the service configuration class
      Returns:
      a matching service configuration, or null if none can be found
    • getExistingServiceConfigurations

      @Deprecated public <T extends org.ehcache.spi.service.ServiceConfiguration<?, ?>> List<T> getExistingServiceConfigurations(Class<T> clazz)
      Deprecated.
      in favor of getServices(Class)
      Returns all ServiceConfigurations of type matching the class passed in.
      Type Parameters:
      T - the type of the service configuration
      Parameters:
      clazz - the service configuration class
      Returns:
      a list with service configurations
    • withClassLoader

      public CacheConfigurationBuilder<K,V> withClassLoader(ClassLoader classLoader)
      Specified by:
      withClassLoader in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withDefaultClassLoader

      public CacheConfigurationBuilder<K,V> withDefaultClassLoader()
      Specified by:
      withDefaultClassLoader in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withResourcePools

      public CacheConfigurationBuilder<K,V> withResourcePools(org.ehcache.config.ResourcePools resourcePools)
      Specified by:
      withResourcePools in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • updateResourcePools

      public CacheConfigurationBuilder<K,V> updateResourcePools(UnaryOperator<org.ehcache.config.ResourcePools> update)
      Specified by:
      updateResourcePools in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withExpiry

      @Deprecated public CacheConfigurationBuilder<K,V> withExpiry(org.ehcache.expiry.Expiry<? super K,? super V> expiry)
      Deprecated.
      Adds Expiry configuration to the returned builder.

      Expiry is what controls data freshness in a cache.

      Parameters:
      expiry - the expiry to use
      Returns:
      a new builder with the added expiry
    • withExpiry

      public CacheConfigurationBuilder<K,V> withExpiry(org.ehcache.expiry.ExpiryPolicy<? super K,? super V> expiry)
      Specified by:
      withExpiry in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • hasConfiguredExpiry

      public boolean hasConfiguredExpiry()
      Indicates whether this builder has configured expiry or not.
      Returns:
      true if expiry configured, false otherwise
    • withLoaderWriter

      public CacheConfigurationBuilder<K,V> withLoaderWriter(org.ehcache.spi.loaderwriter.CacheLoaderWriter<K,V> loaderWriter)
      Specified by:
      withLoaderWriter in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withLoaderWriter

      public CacheConfigurationBuilder<K,V> withLoaderWriter(Class<org.ehcache.spi.loaderwriter.CacheLoaderWriter<K,V>> loaderWriterClass, Object... arguments)
      Specified by:
      withLoaderWriter in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withoutLoaderWriter

      public CacheConfigurationBuilder<K,V> withoutLoaderWriter()
      Specified by:
      withoutLoaderWriter in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withResilienceStrategy

      public CacheConfigurationBuilder<K,V> withResilienceStrategy(org.ehcache.spi.resilience.ResilienceStrategy<K,V> resilienceStrategy)
      Specified by:
      withResilienceStrategy in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withResilienceStrategy

      public CacheConfigurationBuilder<K,V> withResilienceStrategy(Class<? extends org.ehcache.spi.resilience.ResilienceStrategy> resilienceStrategyClass, Object... arguments)
      Specified by:
      withResilienceStrategy in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withDefaultResilienceStrategy

      public CacheConfigurationBuilder<K,V> withDefaultResilienceStrategy()
      Specified by:
      withDefaultResilienceStrategy in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withKeySerializingCopier

      public CacheConfigurationBuilder<K,V> withKeySerializingCopier()
      Specified by:
      withKeySerializingCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withValueSerializingCopier

      public CacheConfigurationBuilder<K,V> withValueSerializingCopier()
      Specified by:
      withValueSerializingCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withKeyCopier

      public CacheConfigurationBuilder<K,V> withKeyCopier(org.ehcache.spi.copy.Copier<K> keyCopier)
      Specified by:
      withKeyCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withKeyCopier

      public CacheConfigurationBuilder<K,V> withKeyCopier(Class<? extends org.ehcache.spi.copy.Copier<K>> keyCopierClass)
      Specified by:
      withKeyCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withoutKeyCopier

      public CacheConfigurationBuilder<K,V> withoutKeyCopier()
      Specified by:
      withoutKeyCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withValueCopier

      public CacheConfigurationBuilder<K,V> withValueCopier(org.ehcache.spi.copy.Copier<V> valueCopier)
      Specified by:
      withValueCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withValueCopier

      public CacheConfigurationBuilder<K,V> withValueCopier(Class<? extends org.ehcache.spi.copy.Copier<V>> valueCopierClass)
      Specified by:
      withValueCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withoutValueCopier

      public CacheConfigurationBuilder<K,V> withoutValueCopier()
      Specified by:
      withoutValueCopier in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withKeySerializer

      public CacheConfigurationBuilder<K,V> withKeySerializer(org.ehcache.spi.serialization.Serializer<K> keySerializer)
      Specified by:
      withKeySerializer in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withKeySerializer

      public CacheConfigurationBuilder<K,V> withKeySerializer(Class<? extends org.ehcache.spi.serialization.Serializer<K>> keySerializerClass)
      Specified by:
      withKeySerializer in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withDefaultKeySerializer

      public CacheConfigurationBuilder<K,V> withDefaultKeySerializer()
      Specified by:
      withDefaultKeySerializer in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withValueSerializer

      public CacheConfigurationBuilder<K,V> withValueSerializer(org.ehcache.spi.serialization.Serializer<V> valueSerializer)
      Specified by:
      withValueSerializer in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withValueSerializer

      public CacheConfigurationBuilder<K,V> withValueSerializer(Class<? extends org.ehcache.spi.serialization.Serializer<V>> valueSerializerClass)
      Specified by:
      withValueSerializer in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withDefaultValueSerializer

      public CacheConfigurationBuilder<K,V> withDefaultValueSerializer()
      Specified by:
      withDefaultValueSerializer in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>
    • withDispatcherConcurrency

      public CacheConfigurationBuilder<K,V> withDispatcherConcurrency(int dispatcherConcurrency)
      Adds StoreEventSourceConfiguration with the specified dispatcher concurrency to the configured builder.
      Parameters:
      dispatcherConcurrency - the level of concurrency in the dispatcher for ordered events
      Returns:
      a new builder with the added configuration
      See Also:
    • withDefaultDispatcherConcurrency

      public CacheConfigurationBuilder<K,V> withDefaultDispatcherConcurrency()
      Restores the default dispatcher concurrency.
      Returns:
      a new builder with the default dispatcher concurrency
      See Also:
    • withEventListenersThreadPool

      public CacheConfigurationBuilder<K,V> withEventListenersThreadPool(String threadPoolAlias)
      Adds a ServiceConfiguration for the CacheEventDispatcherFactory specifying the thread pool alias to use.
      Parameters:
      threadPoolAlias - the thread pool alias to use
      Returns:
      a new builder with the added configuration
      See Also:
    • withDefaultEventListenersThreadPool

      public CacheConfigurationBuilder<K,V> withDefaultEventListenersThreadPool()
      Restores the default event listener thread pool settings.
      Returns:
      a new builder with the default event listener thread pool settings
      See Also:
    • withDiskStoreThreadPool

      public CacheConfigurationBuilder<K,V> withDiskStoreThreadPool(String threadPoolAlias, int concurrency)
      Adds a ServiceConfiguration for the OffHeapDiskStore.Provider indicating thread pool alias and write concurrency.
      Parameters:
      threadPoolAlias - the thread pool alias
      concurrency - the write concurrency
      Returns:
      a new builder with the added configuration
      See Also:
    • withDefaultDiskStoreThreadPool

      public CacheConfigurationBuilder<K,V> withDefaultDiskStoreThreadPool()
      Restores the default disk store thread pool settings.
      Returns:
      a new builder with the default disk store thread pool settings
      See Also:
    • withSizeOfMaxObjectGraph

      @Deprecated public CacheConfigurationBuilder<K,V> withSizeOfMaxObjectGraph(long size)
      Deprecated.
      Adds or updates the DefaultSizeOfEngineConfiguration with the specified object graph maximum size to the configured builder.

      SizeOfEngine is what enables the heap tier to be sized in MemoryUnit.

      Parameters:
      size - the maximum graph size
      Returns:
      a new builder with the added / updated configuration
      See Also:
    • withSizeOfMaxObjectSize

      @Deprecated public CacheConfigurationBuilder<K,V> withSizeOfMaxObjectSize(long size, org.ehcache.config.units.MemoryUnit unit)
      Deprecated.
      Adds or updates the DefaultSizeOfEngineConfiguration with the specified maximum mapping size to the configured builder.

      SizeOfEngine is what enables the heap tier to be sized in MemoryUnit.

      Parameters:
      size - the maximum mapping size
      unit - the memory unit
      Returns:
      a new builder with the added / updated configuration
      See Also:
    • withDefaultSizeOfSettings

      @Deprecated public CacheConfigurationBuilder<K,V> withDefaultSizeOfSettings()
      Deprecated.
      Restores the default size-of settings.
      Returns:
      a new builder with the default size-of settings
      See Also:
    • build

      public org.ehcache.config.CacheConfiguration<K,V> build()
      Specified by:
      build in interface org.ehcache.config.Builder<K>
      Specified by:
      build in interface org.ehcache.config.FluentCacheConfigurationBuilder<K,V,CacheConfigurationBuilder<K,V>>