Class TypesafeConfigurator
- java.lang.Object
-
- com.github.benmanes.caffeine.jcache.configuration.TypesafeConfigurator
-
public final class TypesafeConfigurator extends Object
Static utility methods pertaining to externalizedCaffeineConfigurationentries using the Typesafe Config library.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Set<String>cacheNames(Config config)Retrieves the names of the caches defined in the configuration resource.static ConfigSourceconfigSource()Returns the strategy for loading the configuration.static <K,V>
CaffeineConfiguration<K,V>defaults(Config config)Retrieves the default cache settings from the configuration resource.static <K,V>
Optional<CaffeineConfiguration<K,V>>from(Config config, String cacheName)Retrieves the cache's settings from the configuration resource if defined.static voidsetConfigSource(ConfigSource configSource)Specifies how theConfiginstance should be loaded.static voidsetConfigSource(Supplier<Config> configSource)Specifies how theConfiginstance should be loaded.static voidsetFactoryCreator(FactoryCreator factoryCreator)Specifies howFactoryinstances are created for a given class name.
-
-
-
Method Detail
-
cacheNames
public static Set<String> cacheNames(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(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> Optional<CaffeineConfiguration<K,V>> from(Config config, 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 howFactoryinstances 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(Supplier<Config> configSource)
Specifies how theConfiginstance should be loaded. The default strategy uses the uri provided byCacheManager.getURI()as an optional override location to parse from a file system or classpath resource, or else returnsConfigFactory.load(ClassLoader). 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
-
setConfigSource
public static void setConfigSource(ConfigSource configSource)
Specifies how theConfiginstance should be loaded. The default strategy uses the uri provided byCacheManager.getURI()as an optional override location to parse from a file system or classpath resource, or else returnsConfigFactory.load(ClassLoader). 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 from a uri
-
configSource
public static ConfigSource configSource()
Returns the strategy for loading the configuration.
-
-