Class UserManagedCacheBuilder<K,V,T extends org.ehcache.UserManagedCache<K,V>>

java.lang.Object
org.ehcache.config.builders.UserManagedCacheBuilder<K,V,T>
Type Parameters:
K - the cache key type
V - the cache value type
T - the specific UserManagedCache type
All Implemented Interfaces:
org.ehcache.config.Builder<T>

public class UserManagedCacheBuilder<K,V,T extends org.ehcache.UserManagedCache<K,V>> extends Object implements org.ehcache.config.Builder<T>
The 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 Details

    • build

      public final T build(boolean init) throws IllegalStateException
      Builds the UserManagedCache, 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

      public T build()
      Builds an unitialized UserManagedCache.
      Specified by:
      build in interface org.ehcache.config.Builder<K>
      Returns:
      an uninitialized user managed cache
    • with

      public final <N extends T> UserManagedCacheBuilder<K,V,N> with(UserManagedCacheConfiguration<K,V,N> cfg)
      Specifies the returned UserManagedCache subtype through a specific UserManagedCacheConfiguration which will optionally add configurations to the returned builder.
      Type Parameters:
      N - the subtype of UserManagedCache
      Parameters:
      cfg - the UserManagedCacheConfiguration to use
      Returns:
      a new builder ready to build a more specific subtype of user managed cache
      See Also:
      • PersistentUserManagedCache
      • UserManagedPersistenceContext
    • identifier

      public final UserManagedCacheBuilder<K,V,T> identifier(String 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

      public final UserManagedCacheBuilder<K,V,T> withClassLoader(ClassLoader classLoader)
      Adds a ClassLoader, 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,T> withExpiry(org.ehcache.expiry.Expiry<? super K,? super V> expiry)
      Deprecated.
      Adds Expiry configuration to the returned builder.
      Parameters:
      expiry - the expiry to use
      Returns:
      a new builer with the added expiry
    • withExpiry

      public final UserManagedCacheBuilder<K,V,T> withExpiry(org.ehcache.expiry.ExpiryPolicy<? super K,? super V> expiry)
      Adds ExpiryPolicy configuration to the returned builder.
      Parameters:
      expiry - the expiry to use
      Returns:
      a new builer with the added expiry
    • withEventDispatcher

      public final UserManagedCacheBuilder<K,V,T> withEventDispatcher(org.ehcache.core.events.CacheEventDispatcher<K,V> eventDispatcher)
      Adds an CacheEventDispatcher to 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,T> withEventExecutors(ExecutorService orderedExecutor, ExecutorService unOrderedExecutor)
      Adds the default CacheEventDispatcher using the provided ExecutorService to the returned builder.

      This is one way of providing a mandatory part of supporting event listeners in UserManagedCache

      Parameters:
      orderedExecutor - the ordered event executor service
      unOrderedExecutor - the unordered event executor service
      Returns:
      a new builder with the configured event dispatcher
      See Also:
    • withEventListeners

      public final UserManagedCacheBuilder<K,V,T> withEventListeners(CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration)
      Convenience method to add a CacheEventListenerConfiguration based on the provided CacheEventListenerConfigurationBuilder to 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,T> withEventListeners(org.ehcache.core.events.CacheEventListenerConfiguration<?>... cacheEventListenerConfigurations)
      Adds one or more CacheEventListenerConfiguration to 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,T> withResourcePools(org.ehcache.config.ResourcePools resourcePools)
      Adds a ResourcePools configuration 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,T> withResourcePools(ResourcePoolsBuilder resourcePoolsBuilder)
      Convenience method to add a ResourcePools configuration based on the provided ResourcePoolsBuilder to 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

      public final UserManagedCacheBuilder<K,V,T> withDispatcherConcurrency(int dispatcherConcurrency)
      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,T> withEvictionAdvisor(org.ehcache.config.EvictionAdvisor<K,V> evictionAdvisor)
      Adds an EvictionAdvisor to the returned builder.
      Parameters:
      evictionAdvisor - the eviction advisor to use
      Returns:
      a new builder with the added eviction advisor
    • withLoaderWriter

      public UserManagedCacheBuilder<K,V,T> withLoaderWriter(org.ehcache.spi.loaderwriter.CacheLoaderWriter<K,V> loaderWriter)
      Adds a CacheLoaderWriter to the returned builder.
      Parameters:
      loaderWriter - the cache loader writer to use
      Returns:
      a new builder with the added cache loader writer
    • withKeySerializingCopier

      public UserManagedCacheBuilder<K,V,T> withKeySerializingCopier()
      Adds a configuration for key copying using the key Serializer to the returned builder.
      Returns:
      a new builder with the added configuration
      See Also:
    • withValueSerializingCopier

      public UserManagedCacheBuilder<K,V,T> withValueSerializingCopier()
      Adds a configuration for value copying using the key Serializer to the returned builder.
      Returns:
      a new builder with the added configuration
      See Also:
    • withKeyCopier

      public UserManagedCacheBuilder<K,V,T> withKeyCopier(org.ehcache.spi.copy.Copier<K> keyCopier)
      Adds a configuration for key Copier to the returned builder.
      Parameters:
      keyCopier - the key copier to use
      Returns:
      a new builder with the added key copier configuration
      See Also:
    • withValueCopier

      public UserManagedCacheBuilder<K,V,T> withValueCopier(org.ehcache.spi.copy.Copier<V> valueCopier)
      Adds a configuration for value Copier to 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,T> withKeySerializer(org.ehcache.spi.serialization.Serializer<K> keySerializer)
      Adds a configuration for key Serializer to 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,T> withValueSerializer(org.ehcache.spi.serialization.Serializer<V> valueSerializer)
      Adds a configuration for value Serializer to the returned builder.
      Parameters:
      valueSerializer - the value serializer to use
      Returns:
      a new builder with the added value serializer configuration
    • withSizeOfMaxObjectGraph

      @Deprecated public UserManagedCacheBuilder<K,V,T> withSizeOfMaxObjectGraph(long size)
      Deprecated.
      Adds or updates the DefaultSizeOfEngineProviderConfiguration 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
    • withSizeOfMaxObjectSize

      @Deprecated public UserManagedCacheBuilder<K,V,T> withSizeOfMaxObjectSize(long size, org.ehcache.config.units.MemoryUnit unit)
      Deprecated.
      Adds or updates the DefaultSizeOfEngineProviderConfiguration 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
    • newUserManagedCacheBuilder

      public static <K, V> UserManagedCacheBuilder<K,V,org.ehcache.UserManagedCache<K,V>> newUserManagedCacheBuilder(Class<K> keyType, Class<V> valueType)
      Creates a new UserManagedCacheBuilder.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyType - the cache key type
      valueType - the cache value type
      Returns:
      the new builder
    • using

      public UserManagedCacheBuilder<K,V,T> using(org.ehcache.spi.service.Service service)
      Adds a Service to be made available to the returned builder.

      Note that while Services will be started upon UserManagedCache construction, no other lifecycle operations will be performed on them. It is the responsibility of the developer to properly stop Services 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,T> using(org.ehcache.spi.service.ServiceCreationConfiguration<?,?> serviceConfiguration)
      Adds a ServiceCreationConfiguration, to trigger a service loading and its configuration, to the returned builder.

      Note that while Services will be started upon UserManagedCache construction, no other lifecycle operations will be performed on them. It is the responsibility of the developer to properly stop Services 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: