mirror of
https://github.com/ityouknow/spring-boot-examples.git
synced 2026-05-20 13:31:50 +08:00
34 lines
1.1 KiB
Java
34 lines
1.1 KiB
Java
package com.neo.config;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import org.springframework.cache.CacheManager;
|
|
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
import org.springframework.cache.interceptor.KeyGenerator;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
|
@Configuration
|
|
@EnableCaching
|
|
public class RedisConfig extends CachingConfigurerSupport{
|
|
|
|
@Bean
|
|
public KeyGenerator keyGenerator() {
|
|
return new KeyGenerator() {
|
|
@Override
|
|
public Object generate(Object target, Method method, Object... params) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(target.getClass().getName());
|
|
sb.append(method.getName());
|
|
for (Object obj : params) {
|
|
sb.append(obj.toString());
|
|
}
|
|
return sb.toString();
|
|
}
|
|
};
|
|
}
|
|
} |