All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spring.boxes.mutant.options.GatewayCacheOptions Maven / Gradle / Ivy

The newest version!
package com.spring.boxes.mutant.options;

import com.spring.boxes.dollar.JSONUtils;
import com.spring.boxes.dollar.support.mutant.beans.GatewayInfo;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.Objects;

@Slf4j
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class GatewayCacheOptions extends GatewayRouteOptions {

    private StringRedisTemplate stringRedisTemplate;

    public static GatewayCacheOptions newInstance(StringRedisTemplate stringRedisTemplate) {
        return new GatewayCacheOptions(stringRedisTemplate);
    }

    public GatewayInfo getGateWayInfo(String path, boolean debug) {
        if (StringUtils.isBlank(path)) {
            return null;
        }
        String key = getKey(path, debug);
        String value = stringRedisTemplate.opsForValue().get(key);
        log.info("[Gateway 结构映射] 查询 path:{} value:{}", path, value);
        if (StringUtils.isBlank(value)) {
            return null;
        }
        return JSONUtils.fromJSON(value, GatewayInfo.class);
    }

    public void delGatewayInfo(String path, boolean debug) {
        if (StringUtils.isBlank(path)) {
            return;
        }
        String key = getKey(path, debug);
        log.info("[Gateway 结构映射] 删除 path:{}", path);
        stringRedisTemplate.delete(key);
    }

    public void setGatewayInfo(String path, boolean debug, GatewayInfo gatewayInfo) {
        if (StringUtils.isBlank(path) || Objects.isNull(gatewayInfo)) {
            return;
        }
        String key = getKey(path, debug);
        String val = JSONUtils.toJSON(gatewayInfo);
        log.info("[Gateway 结构映射] 设置 path:{}", path);
        stringRedisTemplate.opsForValue().set(key, StringUtils.trimToEmpty(val));
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy