Class JCacheXAutoConfiguration
- java.lang.Object
-
- io.github.dhruv1110.jcachex.spring.configuration.JCacheXAutoConfiguration
-
@Configuration @ConditionalOnClass({io.github.dhruv1110.jcachex.impl.DefaultCache.class,org.springframework.cache.CacheManager.class}) @ConditionalOnProperty(prefix="jcachex", name="enabled", havingValue="true", matchIfMissing=true) @EnableConfigurationProperties(JCacheXProperties.class) @AutoConfigureBefore(name="org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration") public class JCacheXAutoConfiguration extends Object
Spring Boot auto-configuration for JCacheX.This configuration class automatically sets up JCacheX caching components when the library is present on the classpath. It integrates seamlessly with Spring Boot's auto-configuration system and provides sensible defaults for most use cases.
Auto-Configuration Features:
- Automatic Cache Manager: Creates
JCacheXCacheManager
bean automatically - Property Configuration: Binds configuration from application properties
- Cache Factory: Provides
JCacheXCacheFactory
for programmatic use - Health Indicators: Registers cache health indicators if Spring Boot Actuator is present
- Metrics Integration: Integrates with Micrometer metrics if available
- Graceful Degradation: Falls back gracefully when dependencies are missing
Configuration Properties:
All configuration is done through application properties under the
jcachex
prefix:# Enable/disable JCacheX (default: true) jcachex.enabled=true # Default cache configuration jcachex.default.maximumSize=1000 jcachex.default.expireAfterSeconds=1800 jcachex.default.enableStatistics=true # Cache-specific configuration jcachex.caches.users.maximumSize=5000 jcachex.caches.users.expireAfterSeconds=3600 jcachex.caches.users.evictionStrategy=LRU jcachex.caches.sessions.maximumSize=10000 jcachex.caches.sessions.expireAfterSeconds=1800 jcachex.caches.sessions.evictionStrategy=LFU
Conditional Configuration:
Components are only created when their dependencies are available:
- Core Components: Always created when JCacheX is enabled
- Health Indicators: Only when Spring Boot Actuator is present
- Metrics: Only when Micrometer is present
- JMX: Only when JMX is enabled
Customization:
You can customize the auto-configuration by providing your own beans:
{ @code @Configuration public class CustomCacheConfig { @Bean @Primary public JCacheXCacheManager customCacheManager() { JCacheXCacheManager manager = new JCacheXCacheManager(); manager.setAllowNullValues(false); return manager; }
- Since:
- 1.0.0
- See Also:
JCacheXProperties
,JCacheXCacheManager
,JCacheXCacheFactory
- Automatic Cache Manager: Creates
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JCacheXAutoConfiguration.JCacheXActuatorAutoConfiguration
Configuration for JCacheX actuator integration.static class
JCacheXAutoConfiguration.JCacheXMetricsAutoConfiguration
Configuration for JCacheX metrics integration.
-
Constructor Summary
Constructors Constructor Description JCacheXAutoConfiguration(JCacheXProperties properties)
Creates a new auto-configuration with the specified properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheConfigurationValidator
cacheConfigurationValidator()
Creates a cache configuration validator.Map<String,io.github.dhruv1110.jcachex.Cache<Object,Object>>
configureCaches()
Creates individual cache instances based on configuration.EvictionStrategyFactory
evictionStrategyFactory()
Creates eviction strategy factory for different eviction algorithms.JCacheXAnnotationsAspect
jcacheXAnnotationsAspect(org.springframework.beans.factory.BeanFactory beanFactory)
Registers the AOP aspect that powers @JCacheXCacheable/@JCacheXCacheEvict if Spring AOP is present.JCacheXCacheFactory
jcacheXCacheFactory()
Creates a cache factory bean for programmatic cache creation.JCacheXCacheManager
jcacheXCacheManager()
Creates the primary JCacheX cache manager.
-
-
-
Constructor Detail
-
JCacheXAutoConfiguration
public JCacheXAutoConfiguration(JCacheXProperties properties)
Creates a new auto-configuration with the specified properties.- Parameters:
properties
- the JCacheX properties
-
-
Method Detail
-
jcacheXCacheManager
@Bean("jcacheXCacheManager") @Primary public JCacheXCacheManager jcacheXCacheManager()
Creates the primary JCacheX cache manager. This cache manager integrates with Spring's caching abstraction and provides all the advanced features of JCacheX including multiple eviction strategies, async operations, and comprehensive metrics.- Returns:
- configured JCacheXCacheManager instance
-
configureCaches
@Bean @ConditionalOnProperty(prefix="jcachex", name="autoCreateCaches", havingValue="true", matchIfMissing=true) public Map<String,io.github.dhruv1110.jcachex.Cache<Object,Object>> configureCaches()
Creates individual cache instances based on configuration. This method creates cache beans for each named cache defined in the configuration. These beans can be injected directly or accessed through the cache manager.- Returns:
- map of cache name to cache instance
-
jcacheXCacheFactory
@Bean("jcacheXCacheFactory") @ConditionalOnMissingBean(JCacheXCacheFactory.class) public JCacheXCacheFactory jcacheXCacheFactory()
Creates a cache factory bean for programmatic cache creation. This factory allows creating caches at runtime with custom configurations while still respecting the global configuration defaults.- Returns:
- the cache factory
-
evictionStrategyFactory
@Bean @ConditionalOnMissingBean(EvictionStrategyFactory.class) public EvictionStrategyFactory evictionStrategyFactory()
Creates eviction strategy factory for different eviction algorithms. This factory creates appropriate eviction strategy instances based on string configuration values, making it easy to configure via properties.- Returns:
- the eviction strategy factory
-
cacheConfigurationValidator
@Bean @ConditionalOnMissingBean(CacheConfigurationValidator.class) public CacheConfigurationValidator cacheConfigurationValidator()
Creates a cache configuration validator. This validator ensures that cache configurations are valid and provides helpful error messages for common misconfigurations.- Returns:
- the configuration validator
-
jcacheXAnnotationsAspect
@Bean @ConditionalOnClass(name={"org.aspectj.lang.annotation.Aspect","org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator"}) @ConditionalOnMissingBean(JCacheXAnnotationsAspect.class) public JCacheXAnnotationsAspect jcacheXAnnotationsAspect(org.springframework.beans.factory.BeanFactory beanFactory)
Registers the AOP aspect that powers @JCacheXCacheable/@JCacheXCacheEvict if Spring AOP is present.
-
-