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 { /** * 流程定义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 deploymentCache = deploymentManager.getProcessDefinitionCache(); if (StringUtils.hasText(processDefId)) { deploymentCache.remove(processDefId); } else { deploymentCache.clear(); } return null; } }