xiangpei
2025-04-03 5dd959edf574829a65605ed0c07992c0d88b6b61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.ycl.cmd;
 
import lombok.RequiredArgsConstructor;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache;
import org.flowable.engine.impl.persistence.deploy.DeploymentManager;
import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.repository.Deployment;
import org.springframework.util.StringUtils;
 
/**
 * @author:xp
 * @date:2025/3/17 14:54
 */
public class RemoveDeploymentCacheCMD implements Command<Deployment> {
 
    /**
     * 流程定义id
     */
    private String processDefId;
 
    public RemoveDeploymentCacheCMD(String processDefId) {
        this.processDefId = processDefId;
    }
 
    /**
     * 如果传入了流程定义id,那么只删除特定的缓存。没传就删除所有的缓存
     *
     * @param commandContext
     * @return
     */
    @Override
    public Deployment execute(CommandContext commandContext) {
        DeploymentManager deploymentManager = CommandContextUtil.getProcessEngineConfiguration().getDeploymentManager();
        DeploymentCache<ProcessDefinitionCacheEntry> deploymentCache = deploymentManager.getProcessDefinitionCache();
 
        if (StringUtils.hasText(processDefId)) {
            deploymentCache.remove(processDefId);
        } else {
            deploymentCache.clear();
        }
        return null;
    }
}