Class UserManagedCacheBuilder<K,V,T extends org.ehcache.UserManagedCache<K,V>>
- Type Parameters:
K- the cache key typeV- the cache value typeT- the specificUserManagedCachetype
- All Implemented Interfaces:
org.ehcache.config.Builder<T>
UserManagedCacheBuilder enables building UserManagedCaches using a fluent style.
UserManagedCaches are Caches that are not linked to a CacheManager.
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 an unitializedUserManagedCache.final Tbuild(boolean init) Builds theUserManagedCache, initializing it if requested.final UserManagedCacheBuilder<K,V, T> identifier(String identifier) Adds an identifier to the returned builder.static <K,V> UserManagedCacheBuilder<K, V, org.ehcache.UserManagedCache<K, V>> newUserManagedCacheBuilder(Class<K> keyType, Class<V> valueType) Creates a newUserManagedCacheBuilder.using(org.ehcache.spi.service.Service service) Adds aServiceto be made available to the returned builder.using(org.ehcache.spi.service.ServiceCreationConfiguration<?, ?> serviceConfiguration) Adds aServiceCreationConfiguration, to trigger a service loading and its configuration, to the returned builder.final <N extends T>
UserManagedCacheBuilder<K,V, N> with(UserManagedCacheConfiguration<K, V, N> cfg) Specifies the returnedUserManagedCachesubtype through a specificUserManagedCacheConfigurationwhich will optionally add configurations to the returned builder.final UserManagedCacheBuilder<K,V, T> withClassLoader(ClassLoader classLoader) Adds aClassLoader, to load non Ehcache types, to the returned builder.final UserManagedCacheBuilder<K,V, T> withDispatcherConcurrency(int dispatcherConcurrency) Adds a configuration for dispatcher concurrency in event processing.final UserManagedCacheBuilder<K,V, T> withEventDispatcher(org.ehcache.core.events.CacheEventDispatcher<K, V> eventDispatcher) Adds anCacheEventDispatcherto the returned builder.final UserManagedCacheBuilder<K,V, T> withEventExecutors(ExecutorService orderedExecutor, ExecutorService unOrderedExecutor) Adds the defaultCacheEventDispatcherusing the providedExecutorServiceto the returned builder.final UserManagedCacheBuilder<K,V, T> withEventListeners(CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration) Convenience method to add aCacheEventListenerConfigurationbased on the providedCacheEventListenerConfigurationBuilderto the returned builder.final UserManagedCacheBuilder<K,V, T> withEventListeners(org.ehcache.core.events.CacheEventListenerConfiguration<?>... cacheEventListenerConfigurations) Adds one or moreCacheEventListenerConfigurationto the returned builder.withEvictionAdvisor(org.ehcache.config.EvictionAdvisor<K, V> evictionAdvisor) Adds anEvictionAdvisorto the returned builder.final UserManagedCacheBuilder<K,V, T> withExpiry(org.ehcache.expiry.Expiry<? super K, ? super V> expiry) Deprecated.final UserManagedCacheBuilder<K,V, T> withExpiry(org.ehcache.expiry.ExpiryPolicy<? super K, ? super V> expiry) AddsExpiryPolicyconfiguration to the returned builder.withKeyCopier(org.ehcache.spi.copy.Copier<K> keyCopier) Adds a configuration for keyCopierto the returned builder.withKeySerializer(org.ehcache.spi.serialization.Serializer<K> keySerializer) Adds a configuration for keySerializerto the returned builder.Adds a configuration forkey copyingusing the keySerializerto the returned builder.withLoaderWriter(org.ehcache.spi.loaderwriter.CacheLoaderWriter<K, V> loaderWriter) Adds aCacheLoaderWriterto the returned builder.final UserManagedCacheBuilder<K,V, T> withResourcePools(ResourcePoolsBuilder resourcePoolsBuilder) Convenience method to add aResourcePoolsconfiguration based on the providedResourcePoolsBuilderto the returned builder.final UserManagedCacheBuilder<K,V, T> withResourcePools(org.ehcache.config.ResourcePools resourcePools) Adds aResourcePoolsconfiguration to the returned builder.withSizeOfMaxObjectGraph(long size) Deprecated.withSizeOfMaxObjectSize(long size, org.ehcache.config.units.MemoryUnit unit) Deprecated.withValueCopier(org.ehcache.spi.copy.Copier<V> valueCopier) Adds a configuration for valueCopierto the returned builder.withValueSerializer(org.ehcache.spi.serialization.Serializer<V> valueSerializer) Adds a configuration for valueSerializerto the returned builder.Adds a configuration forvalue copyingusing the keySerializerto the returned builder.
-
Method Details
-
build
Builds theUserManagedCache, initializing it if requested.- Parameters:
init- whether to initialize or not the cache before returning- Returns:
- a user managed cache
- Throws:
IllegalStateException- if the user managed cache cannot be built
-
build
Builds an unitializedUserManagedCache.- Specified by:
buildin interfaceorg.ehcache.config.Builder<K>- Returns:
- an uninitialized user managed cache
-
with
public final <N extends T> UserManagedCacheBuilder<K,V, withN> (UserManagedCacheConfiguration<K, V, N> cfg) Specifies the returnedUserManagedCachesubtype through a specificUserManagedCacheConfigurationwhich will optionally add configurations to the returned builder.- Type Parameters:
N- the subtype ofUserManagedCache- Parameters:
cfg- theUserManagedCacheConfigurationto use- Returns:
- a new builder ready to build a more specific subtype of user managed cache
- See Also:
-
PersistentUserManagedCacheUserManagedPersistenceContext
-
identifier
Adds an identifier to the returned builder.The identifier will be used in services and logging the way a cache alias would be inside a
CacheManager- Parameters:
identifier- the identifier- Returns:
- a new builder with the added identifier
-
withClassLoader
Adds aClassLoader, to load non Ehcache types, to the returned builder.- Parameters:
classLoader- the class loader to use- Returns:
- a new builder with the added class loader
-
withExpiry
@Deprecated public final UserManagedCacheBuilder<K,V, withExpiryT> (org.ehcache.expiry.Expiry<? super K, ? super V> expiry) Deprecated.UsewithExpiry(ExpiryPolicy)insteadAddsExpiryconfiguration to the returned builder.- Parameters:
expiry- the expiry to use- Returns:
- a new builer with the added expiry
-
withExpiry
public final UserManagedCacheBuilder<K,V, withExpiryT> (org.ehcache.expiry.ExpiryPolicy<? super K, ? super V> expiry) AddsExpiryPolicyconfiguration to the returned builder.- Parameters:
expiry- the expiry to use- Returns:
- a new builer with the added expiry
-
withEventDispatcher
public final UserManagedCacheBuilder<K,V, withEventDispatcherT> (org.ehcache.core.events.CacheEventDispatcher<K, V> eventDispatcher) Adds anCacheEventDispatcherto the returned builder.This is one way of providing a mandatory part of supporting event listeners in
UserManagedCache- Parameters:
eventDispatcher- the event dispatcher to use- Returns:
- a new builder with the configured event dispatcher
- See Also:
-
withEventExecutors
public final UserManagedCacheBuilder<K,V, withEventExecutorsT> (ExecutorService orderedExecutor, ExecutorService unOrderedExecutor) Adds the defaultCacheEventDispatcherusing the providedExecutorServiceto the returned builder.This is one way of providing a mandatory part of supporting event listeners in
UserManagedCache- Parameters:
orderedExecutor- the ordered event executor serviceunOrderedExecutor- the unordered event executor service- Returns:
- a new builder with the configured event dispatcher
- See Also:
-
withEventListeners
public final UserManagedCacheBuilder<K,V, withEventListenersT> (CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration) Convenience method to add aCacheEventListenerConfigurationbased on the providedCacheEventListenerConfigurationBuilderto the returned builder.- Parameters:
cacheEventListenerConfiguration- the builder to get the configuration from- Returns:
- a new builder with the added event listener configuration
- See Also:
-
withEventListeners
public final UserManagedCacheBuilder<K,V, withEventListenersT> (org.ehcache.core.events.CacheEventListenerConfiguration<?>... cacheEventListenerConfigurations) Adds one or moreCacheEventListenerConfigurationto the returned builder.- Parameters:
cacheEventListenerConfigurations- the cache event listener configurations- Returns:
- a new builders with the added event listener configurations
- See Also:
-
withResourcePools
public final UserManagedCacheBuilder<K,V, withResourcePoolsT> (org.ehcache.config.ResourcePools resourcePools) Adds aResourcePoolsconfiguration to the returned builder.- Parameters:
resourcePools- the resource pools to use- Returns:
- a new builder with the configured resource pools
- See Also:
-
withResourcePools
public final UserManagedCacheBuilder<K,V, withResourcePoolsT> (ResourcePoolsBuilder resourcePoolsBuilder) Convenience method to add aResourcePoolsconfiguration based on the providedResourcePoolsBuilderto the returned builder.- Parameters:
resourcePoolsBuilder- the builder to get the resource pools from- Returns:
- a new builder with the configured resource pools
- See Also:
-
withDispatcherConcurrency
Adds a configuration for dispatcher concurrency in event processing.- Parameters:
dispatcherConcurrency- the dispatcher concurrency level- Returns:
- a new builder with the added configuration
-
withEvictionAdvisor
public UserManagedCacheBuilder<K,V, withEvictionAdvisorT> (org.ehcache.config.EvictionAdvisor<K, V> evictionAdvisor) Adds anEvictionAdvisorto the returned builder.- Parameters:
evictionAdvisor- the eviction advisor to use- Returns:
- a new builder with the added eviction advisor
-
withLoaderWriter
public UserManagedCacheBuilder<K,V, withLoaderWriterT> (org.ehcache.spi.loaderwriter.CacheLoaderWriter<K, V> loaderWriter) Adds aCacheLoaderWriterto the returned builder.- Parameters:
loaderWriter- the cache loader writer to use- Returns:
- a new builder with the added cache loader writer
-
withKeySerializingCopier
Adds a configuration forkey copyingusing the keySerializerto the returned builder.- Returns:
- a new builder with the added configuration
- See Also:
-
withValueSerializingCopier
Adds a configuration forvalue copyingusing the keySerializerto the returned builder.- Returns:
- a new builder with the added configuration
- See Also:
-
withKeyCopier
Adds a configuration for keyCopierto the returned builder.- Parameters:
keyCopier- the key copier to use- Returns:
- a new builder with the added key copier configuration
- See Also:
-
withValueCopier
Adds a configuration for valueCopierto the returned builder.- Parameters:
valueCopier- the value copier to use- Returns:
- a new builder with the added value copier configuration
- See Also:
-
withKeySerializer
public UserManagedCacheBuilder<K,V, withKeySerializerT> (org.ehcache.spi.serialization.Serializer<K> keySerializer) Adds a configuration for keySerializerto the returned builder.- Parameters:
keySerializer- the key serializer to use- Returns:
- a new builder with the added key serializer configuration
-
withValueSerializer
public UserManagedCacheBuilder<K,V, withValueSerializerT> (org.ehcache.spi.serialization.Serializer<V> valueSerializer) Adds a configuration for valueSerializerto the returned builder.- Parameters:
valueSerializer- the value serializer to use- Returns:
- a new builder with the added value serializer configuration
-
withSizeOfMaxObjectGraph
Deprecated.Adds or updates theDefaultSizeOfEngineProviderConfigurationwith the specified object graph maximum size to the configured builder.SizeOfEngineis what enables the heap tier to be sized inMemoryUnit.- Parameters:
size- the maximum graph size- Returns:
- a new builder with the added / updated configuration
-
withSizeOfMaxObjectSize
@Deprecated public UserManagedCacheBuilder<K,V, withSizeOfMaxObjectSizeT> (long size, org.ehcache.config.units.MemoryUnit unit) Deprecated.Adds or updates theDefaultSizeOfEngineProviderConfigurationwith the specified maximum mapping size to the configured builder.SizeOfEngineis what enables the heap tier to be sized inMemoryUnit.- Parameters:
size- the maximum mapping sizeunit- the memory unit- Returns:
- a new builder with the added / updated configuration
-
newUserManagedCacheBuilder
public static <K,V> UserManagedCacheBuilder<K,V, newUserManagedCacheBuilderorg.ehcache.UserManagedCache<K, V>> (Class<K> keyType, Class<V> valueType) Creates a newUserManagedCacheBuilder.- Type Parameters:
K- the key typeV- the value type- Parameters:
keyType- the cache key typevalueType- the cache value type- Returns:
- the new builder
-
using
Adds aServiceto be made available to the returned builder.Note that while
Services will be started uponUserManagedCacheconstruction, no other lifecycle operations will be performed on them. It is the responsibility of the developer to properly stopServices once they are no longer required.- Parameters:
service- the service to add- Returns:
- a new builder with the added service
- See Also:
-
using
public UserManagedCacheBuilder<K,V, usingT> (org.ehcache.spi.service.ServiceCreationConfiguration<?, ?> serviceConfiguration) Adds aServiceCreationConfiguration, to trigger a service loading and its configuration, to the returned builder.Note that while
Services will be started uponUserManagedCacheconstruction, no other lifecycle operations will be performed on them. It is the responsibility of the developer to properly stopServices once they are no longer required. Which means that this method should not be used to get services that require a stop.- Parameters:
serviceConfiguration- the service creation configuration to add- Returns:
- a new builder with the added service creation configuration
- See Also:
-
withExpiry(ExpiryPolicy)instead