Skip to content

Commit

Permalink
perf($Starter): abstract Redis configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Jan 29, 2021
1 parent 5ae8a56 commit 9687151
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@
@ConditionalOnWebApplication
@AutoConfigureOrder(Integer.MIN_VALUE)
@EnableConfigurationProperties(MafConfiguration.class)
@Import({MyBatisPlusConfiguration.class, Swagger2Configuration.class})
@Import({
MyBatisPlusConfiguration.class,
RedisConfiguration.class,
Swagger2Configuration.class
})
public class MafAutoConfiguration {
@PostConstruct
public void postConstruct() {
Expand Down Expand Up @@ -173,18 +177,6 @@ public JwtConfiguration jwtConfiguration(MafProjectProperty mafProjectProperty)
return new JwtConfiguration(mafProjectProperty);
}

@Bean
public RedisCachingConfiguration redisCachingConfiguration(RedisConnectionFactory redisConnectionFactory) {
log.warn("Initial bean: '{}'", RedisCachingConfiguration.class.getSimpleName());
return new RedisCachingConfiguration(redisConnectionFactory);
}

@Bean
public RedisConfiguration redisConfiguration(ObjectMapper objectMapper) {
log.warn("Initial bean: '{}'", RedisConfiguration.class.getSimpleName());
return new RedisConfiguration(objectMapper);
}

@Bean
@LoadBalanced
public RestTemplate restTemplate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private void postConstruct() {
@Bean
@Override
public CacheManager cacheManager() {
log.warn("Initial bean: '{}'", CacheManager.class.getSimpleName());
RedisCacheConfiguration cacheConfiguration = defaultCacheConfig()
.disableCachingNullValues()
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(
Expand All @@ -54,12 +55,14 @@ public CacheManager cacheManager() {
@Bean
@Override
public CacheResolver cacheResolver() {
log.warn("Initial bean: '{}'", SimpleCacheResolver.class.getSimpleName());
return new SimpleCacheResolver(Objects.requireNonNull(cacheManager()));
}

@Bean
@Override
public KeyGenerator keyGenerator() {
log.warn("Initial bean: '{}'", KeyGenerator.class.getSimpleName());
return (target, method, params) -> {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(target.getClass().getName()).append("#").append(method.getName());
Expand All @@ -73,6 +76,7 @@ public KeyGenerator keyGenerator() {
@Bean
@Override
public CacheErrorHandler errorHandler() {
log.warn("Initial bean: '{}'", CacheErrorHandler.class.getSimpleName());
return new SimpleCacheErrorHandler();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.jmsoftware.maf.springbootstarter.redis;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jmsoftware.maf.springbootstarter.configuration.Swagger2Configuration;
import com.jmsoftware.maf.springbootstarter.database.MyBatisPlusConfiguration;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
Expand All @@ -24,6 +28,9 @@
@Slf4j
@Configuration
@RequiredArgsConstructor
@Import({
RedisCachingConfiguration.class
})
public class RedisConfiguration {
private final ObjectMapper objectMapper;

Expand Down

0 comments on commit 9687151

Please sign in to comment.