...
|
...
|
@@ -16,6 +16,7 @@ import com.yohoufo.resource.util.RedisLoadingCache; |
|
|
import com.yohoufo.resource.util.ValueSerializer;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
...
|
...
|
@@ -28,7 +29,7 @@ import java.util.concurrent.TimeUnit; |
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ConfigTypeServiceImpl implements IConfigTypeService {
|
|
|
public class ConfigTypeServiceImpl implements IConfigTypeService, InitializingBean {
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigTypeServiceImpl.class);
|
|
|
|
|
|
private LocalCache localCache = new LocalCache();
|
...
|
...
|
@@ -44,41 +45,46 @@ public class ConfigTypeServiceImpl implements IConfigTypeService { |
|
|
@Redis("yohoNoSyncRedis")
|
|
|
private YHValueOperations valueOperations;
|
|
|
|
|
|
private final RedisLoadingCache<String, ConfigType> codeConfigTypeRedisCache = RedisCacheBuilder.newBuilder()
|
|
|
.withYhRedis(redisTemplate, valueOperations)
|
|
|
.withExpire(5, TimeUnit.SECONDS)
|
|
|
.withKeySerializer(new KeySerializer<String>() {
|
|
|
@Override
|
|
|
public RedisKeyBuilder serialize(String obj) {
|
|
|
return new RedisKeyBuilder().appendFixed("ufo:resources:configType:code:").appendVar(obj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String deserialize(RedisKeyBuilder keyBuilder) {
|
|
|
return keyBuilder.getKey().substring(keyBuilder.getKey().lastIndexOf("ufo:resources:configType:") + 1);
|
|
|
}
|
|
|
})
|
|
|
.withValueSerializer(new ValueSerializer<ConfigType>() {
|
|
|
|
|
|
@Override
|
|
|
public String serialize(ConfigType obj) {
|
|
|
return JSONObject.toJSONString(obj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ConfigType deserialize(String objectData) {
|
|
|
return JSONObject.parseObject(objectData, ConfigType.class);
|
|
|
}
|
|
|
|
|
|
})
|
|
|
.build(new CacheLoader<String, ConfigType>() {
|
|
|
|
|
|
@Override
|
|
|
public ConfigType load(String code) throws Exception {
|
|
|
return configTypeMapper.selectByCode(code);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
private RedisLoadingCache<String, ConfigType> codeConfigTypeRedisCache;
|
|
|
|
|
|
@Override
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
codeConfigTypeRedisCache = RedisCacheBuilder.newBuilder()
|
|
|
.withYhRedis(redisTemplate, valueOperations)
|
|
|
.withExpire(5, TimeUnit.SECONDS)
|
|
|
.withKeySerializer(new KeySerializer<String>() {
|
|
|
@Override
|
|
|
public RedisKeyBuilder serialize(String obj) {
|
|
|
return new RedisKeyBuilder().appendFixed("ufo:resources:configType:code:").appendVar(obj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String deserialize(RedisKeyBuilder keyBuilder) {
|
|
|
return keyBuilder.getKey().substring(keyBuilder.getKey().lastIndexOf("ufo:resources:configType:") + 1);
|
|
|
}
|
|
|
})
|
|
|
.withValueSerializer(new ValueSerializer<ConfigType>() {
|
|
|
|
|
|
@Override
|
|
|
public String serialize(ConfigType obj) {
|
|
|
return JSONObject.toJSONString(obj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ConfigType deserialize(String objectData) {
|
|
|
return JSONObject.parseObject(objectData, ConfigType.class);
|
|
|
}
|
|
|
|
|
|
})
|
|
|
.build(new CacheLoader<String, ConfigType>() {
|
|
|
|
|
|
@Override
|
|
|
public ConfigType load(String code) throws Exception {
|
|
|
return configTypeMapper.selectByCode(code);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
...
|
...
|
@@ -126,4 +132,5 @@ public class ConfigTypeServiceImpl implements IConfigTypeService { |
|
|
return rows;
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|