Class TypesafeConfigurator
- java.lang.Object
-
- com.github.benmanes.caffeine.jcache.configuration.TypesafeConfigurator
-
public final class TypesafeConfigurator extends java.lang.Object
Static utility methods pertaining to externalizedCaffeineConfiguration
entries using the Typesafe Config library.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TypesafeConfigurator.Configurator<K,V>
A one-shot builder for creating a configuration instance.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.function.Supplier<com.typesafe.config.Config>
configSource
(package private) static FactoryCreator
factoryCreator
(package private) static java.util.logging.Logger
logger
-
Constructor Summary
Constructors Modifier Constructor Description private
TypesafeConfigurator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Set<java.lang.String>
cacheNames(com.typesafe.config.Config config)
Retrieves the names of the caches defined in the configuration resource.static java.util.function.Supplier<com.typesafe.config.Config>
configSource()
Returns the strategy for loading the configuration.static <K,V>
CaffeineConfiguration<K,V>defaults(com.typesafe.config.Config config)
Retrieves the default cache settings from the configuration resource.static <K,V>
java.util.Optional<CaffeineConfiguration<K,V>>from(com.typesafe.config.Config config, java.lang.String cacheName)
Retrieves the cache's settings from the configuration resource if defined.static void
setConfigSource(java.util.function.Supplier<com.typesafe.config.Config> configSource)
Specifies how theConfig
instance should be loaded.static void
setFactoryCreator(FactoryCreator factoryCreator)
Specifies howFactory
instances are created for a given class name.
-
-
-
Field Detail
-
logger
static final java.util.logging.Logger logger
-
factoryCreator
static FactoryCreator factoryCreator
-
configSource
static java.util.function.Supplier<com.typesafe.config.Config> configSource
-
-
Method Detail
-
cacheNames
public static java.util.Set<java.lang.String> cacheNames(com.typesafe.config.Config config)
Retrieves the names of the caches defined in the configuration resource.- Parameters:
config
- the configuration resource- Returns:
- the names of the configured caches
-
defaults
public static <K,V> CaffeineConfiguration<K,V> defaults(com.typesafe.config.Config config)
Retrieves the default cache settings from the configuration resource.- Type Parameters:
K
- the type of keys maintained the cacheV
- the type of cached values- Parameters:
config
- the configuration resource- Returns:
- the default configuration for a cache
-
from
public static <K,V> java.util.Optional<CaffeineConfiguration<K,V>> from(com.typesafe.config.Config config, java.lang.String cacheName)
Retrieves the cache's settings from the configuration resource if defined.- Type Parameters:
K
- the type of keys maintained the cacheV
- the type of cached values- Parameters:
config
- the configuration resourcecacheName
- the name of the cache- Returns:
- the configuration for the cache
-
setFactoryCreator
@Inject public static void setFactoryCreator(FactoryCreator factoryCreator)
Specifies howFactory
instances are created for a given class name. The default strategy usesClass.newInstance()
and requires the class has a no-args constructor.- Parameters:
factoryCreator
- the strategy for creating a factory
-
setConfigSource
public static void setConfigSource(java.util.function.Supplier<com.typesafe.config.Config> configSource)
Specifies how theConfig
instance should be loaded. The default strategy usesConfigFactory.load()
. The configuration is retrieved on-demand, allowing for it to be reloaded, and it is assumed that the source caches it as needed.- Parameters:
configSource
- the strategy for loading the configuration
-
configSource
public static java.util.function.Supplier<com.typesafe.config.Config> configSource()
Returns the strategy for loading the configuration.
-
-