Package org.ehcache.config.builders
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 Summary
Modifier and TypeMethodDescriptionbuild()Builds aCacheManageror a subtype of it uninitialized.build(boolean init) Builds aCacheManageror a subtype of it and initializes it if requested.static org.ehcache.CacheManagernewCacheManager(org.ehcache.config.Configuration configuration) Creates a newCacheManagerbased on the provided configuration.static CacheManagerBuilder<org.ehcache.CacheManager>Creates a newCacheManagerBuilderstatic CacheManagerConfiguration<org.ehcache.PersistentCacheManager>persistence(File rootDirectory) Convenience method to get aCacheManagerConfigurationfor aPersistentCacheManagerstored on disk.static CacheManagerConfiguration<org.ehcache.PersistentCacheManager>persistence(String rootDirectory) Convenience method to get aCacheManagerConfigurationfor aPersistentCacheManagerstored on disk.replacing(org.ehcache.spi.service.ServiceCreationConfiguration<?, ?> overwriteServiceConfiguration) Deprecated.sharedResources(org.ehcache.config.Builder<? extends org.ehcache.config.ResourcePools> sharedResourcePoolsBuilder) Defines aResourcePools, containing one or moreResourcePools that configured caches can reference, such that their caching requirements will be managed via the shared pool.using(org.ehcache.spi.service.Service service) Adds aServiceinstance to the returned builder.using(org.ehcache.spi.service.ServiceCreationConfiguration<?, ?> serviceConfiguration) Adds aServiceCreationConfigurationto the returned builder.<N extends T>
CacheManagerBuilder<N>with(org.ehcache.config.Builder<? extends CacheManagerConfiguration<N>> cfgBuilder) Convenience method to specialize the returnedCacheManagersubtype through aCacheManagerConfigurationbuilt using the providedBuilder.<N extends T>
CacheManagerBuilder<N>with(CacheManagerConfiguration<N> cfg) Specializes the returnedCacheManagersubtype through a specificCacheManagerConfigurationwhich will optionally add configurations to the returned builder.<K,V> CacheManagerBuilder<T> withCache(String alias, org.ehcache.config.Builder<? extends org.ehcache.config.CacheConfiguration<K, V>> configurationBuilder) Convenience method to add aCacheConfigurationlinked to the specified alias to the returned builder by building it from the providedBuilder.<K,V> CacheManagerBuilder<T> Adds aCacheConfigurationlinked to the specified alias to the returned builder.withClassLoader(ClassLoader classLoader) Adds aClassLoader, to use for non Ehcache types, to the returned builder<C> CacheManagerBuilder<T>withCopier(Class<C> clazz, Class<? extends org.ehcache.spi.copy.Copier<C>> copier) Adds a defaultCopierfor the specified type to the returned builder.withDefaultDiskStoreThreadPool(String threadPoolAlias) Adds aOffHeapDiskStoreProviderConfiguration, that specifies the thread pool to use, to the returned builder.withDefaultEventListenersThreadPool(String threadPoolAlias) Adds aCacheEventDispatcherFactoryConfiguration, that specifies the thread pool to use, to the returned builder.withDefaultSizeOfMaxObjectGraph(long size) Deprecated.withDefaultSizeOfMaxObjectSize(long size, org.ehcache.config.units.MemoryUnit unit) Deprecated.withDefaultWriteBehindThreadPool(String threadPoolAlias) Adds aWriteBehindProviderConfiguration, that specifies the thread pool to use, to the returned builder.<C> CacheManagerBuilder<T>withSerializer(Class<C> clazz, Class<? extends org.ehcache.spi.serialization.Serializer<C>> serializer) Adds a defaultSerializerfor the specified type to the returned builder.
-
Method Details
-
build
Builds aCacheManageror a subtype of it and initializes it if requested.- Parameters:
init- whether the returnedCacheManageris to be initialized or not- Returns:
- a
CacheManageror a subtype of it
-
build
Builds aCacheManageror a subtype of it uninitialized.- Specified by:
buildin interfaceorg.ehcache.config.Builder<T extends org.ehcache.CacheManager>- Returns:
- a
CacheManageror a subtype of it uninitialized
-
newCacheManager
public static org.ehcache.CacheManager newCacheManager(org.ehcache.config.Configuration configuration) Creates a newCacheManagerbased on the provided configuration. The returnedCacheManageris 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 aCacheConfigurationlinked to the specified alias to the returned builder.- Type Parameters:
K- the cache key typeV- the cache value type- Parameters:
alias- the cache aliasconfiguration- theCacheConfiguration- 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 aCacheConfigurationlinked to the specified alias to the returned builder by building it from the providedBuilder.- Type Parameters:
K- the cache key typeV- the cache value type- Parameters:
alias- the cache aliasconfigurationBuilder- theBuilderto getCacheConfigurationfrom- Returns:
- a new builder with the added cache configuration
- See Also:
-
with
Specializes the returnedCacheManagersubtype through a specificCacheManagerConfigurationwhich will optionally add configurations to the returned builder.- Type Parameters:
N- the subtype ofCacheManager- Parameters:
cfg- theCacheManagerConfigurationto use- Returns:
- a new builder ready to build a more specific subtype of cache manager
- See Also:
-
persistence(String)PersistentCacheManagerCacheManagerPersistenceConfiguration
-
with
public <N extends T> CacheManagerBuilder<N> with(org.ehcache.config.Builder<? extends CacheManagerConfiguration<N>> cfgBuilder) Convenience method to specialize the returnedCacheManagersubtype through aCacheManagerConfigurationbuilt using the providedBuilder.- Parameters:
cfgBuilder- theBuilderto get theCacheManagerConfigurationfrom- Returns:
- a new builder ready to build a more specific subtype of cache manager
- See Also:
-
using
Adds aServiceinstance to the returned builder.The service instance will be used by the constructed
CacheManager.- Parameters:
service- theServiceto 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 defaultCopierfor the specified type to the returned builder.- Type Parameters:
C- the type which can be copied- Parameters:
clazz- theClassfor which the copier iscopier- theCopierinstance- 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 defaultSerializerfor the specified type to the returned builder.- Type Parameters:
C- the type which can be serialized- Parameters:
clazz- theClassfor which the serializer isserializer- theSerializerinstance- Returns:
- a new builder with the added default serializer
-
withDefaultSizeOfMaxObjectGraph
Deprecated.Adds a defaultSizeOfEngineconfiguration, 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 defaultSizeOfEngineconfiguration, that limits the max object size, to the returned builder.- Parameters:
size- the max object sizeunit- the max object size unit- Returns:
- a new builder with the added configuration
-
withDefaultWriteBehindThreadPool
Adds aWriteBehindProviderConfiguration, 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
Adds aOffHeapDiskStoreProviderConfiguration, 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
Adds aCacheEventDispatcherFactoryConfiguration, 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 aServiceCreationConfigurationto 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- theServiceCreationConfigurationto 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 ofusing(ServiceCreationConfiguration)whose refined contract matches this oneReplaces an existingServiceCreationConfigurationof the same type on the returned builder.Duplicate service creation configuration will cause a cache manager to fail to initialize.
- Parameters:
overwriteServiceConfiguration- the newServiceCreationConfigurationto use- Returns:
- a new builder with the replaced configuration
-
withClassLoader
Adds aClassLoader, 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
Creates a newCacheManagerBuilder- Returns:
- the cache manager builder
-
persistence
public static CacheManagerConfiguration<org.ehcache.PersistentCacheManager> persistence(String rootDirectory) Convenience method to get aCacheManagerConfigurationfor aPersistentCacheManagerstored 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:
-
ResourcePoolsBuilder.disk(long, MemoryUnit, boolean)with(CacheManagerConfiguration)PersistentCacheManager
-
persistence
public static CacheManagerConfiguration<org.ehcache.PersistentCacheManager> persistence(File rootDirectory) Convenience method to get aCacheManagerConfigurationfor aPersistentCacheManagerstored 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:
-
ResourcePoolsBuilder.disk(long, MemoryUnit, boolean)with(CacheManagerConfiguration)PersistentCacheManager
-
using(ServiceCreationConfiguration)whose refined contract matches this one