Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringBoot配置项设置本地缓存为false不生效 #27

Open
XuHaodong-github opened this issue Sep 25, 2024 · 1 comment
Open

SpringBoot配置项设置本地缓存为false不生效 #27

XuHaodong-github opened this issue Sep 25, 2024 · 1 comment

Comments

@XuHaodong-github
Copy link

XuHaodong-github commented Sep 25, 2024

@Configuration
public class IdAutoConfig {
    @Value("${mybatis-plus.zookeeper.serverLists}")
    private String zkServerLists;

    @Bean
    public IdentifierGenerator idGenerator() {
        // 设置zk服务器地址
        ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration();
        zookeeperConfiguration.setServerLists(zkServerLists);
        // 设置本地缓存和序列化方式
        ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();
        applicationConfiguration.setCacheable(false);
        applicationConfiguration.setSerialize(SerializeStrategy.SERIALIZE_JSON_JACKSON);
        // 创建idworker实例
        return new ImadcnIdentifierGenerator(zookeeperConfiguration, applicationConfiguration);
    }
}

tmp/idworker/default.cache
每次项目启动运行之后还是会在项目目录里生成这个缓存文件,有什么方法能够不生成吗

@XuHaodong-github
Copy link
Author

XuHaodong-github commented Sep 25, 2024

ZookeeperWorkerRegister

// 无本地信息或者缓存数据不匹配,开始向ZK申请节点机器ID
for (int workerId = 0; workerId < MAX_WORKER_NUM; workerId++) {
    workerIdStr = String.valueOf(workerId);
    if (!children.contains(workerIdStr)) { // 申请成功
        NodeInfo applyNodeInfo = createNodeInfo(getNodePath().getGroupName(), workerId);
        getNodePath().setWorkerId(applyNodeInfo.getWorkerId());
        // 保存ZK节点信息,保存本地缓存,开启定时上报任务
        saveZookeeperNodeInfo(getNodePath().getWorkerIdPath(), applyNodeInfo);
        saveLocalNodeInfo(applyNodeInfo);
        executeUploadNodeInfoTask(getNodePath().getWorkerIdPath(), applyNodeInfo);
        return applyNodeInfo.getWorkerId();
    }
}

saveLocalNodeInfo可以根据isCacheable去掉吗,本地每次运行完git总会多一个uncommitted的文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant