flowable 清除流程本地缓存_flowable缓存过期时间-程序员宅基地

技术标签: # flowable  工作流  activiti  flowable  spring cloud  

flowable 清除流程本地缓存

flowable 或者 activity 修改流程图属性后,需要清除本地缓存,可以用以下方法来实现。

一、清除缓存 Cmd

package indi.tudan.modules.flowable.common.cmd;

import indi.tudan.common.core.utils.StringUtils;
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 java.io.Serializable;

/**
 * 清除流程缓存
 *
 * @author wangtan
 * @date 2021-12-29 10:11:25
 * @since 1.0.0
 */
public class DeploymentCacheCmd implements Command<Deployment>, Serializable {
    

    private static final long serialVersionUID = 1L;
    private final String definitionId;

    public DeploymentCacheCmd(String definitionId) {
    
        this.definitionId = definitionId;
    }

    @Override
    public Deployment execute(CommandContext commandContext) {
    

        DeploymentManager deploymentManager = CommandContextUtil.getProcessEngineConfiguration().getDeploymentManager();
        DeploymentCache<ProcessDefinitionCacheEntry> deploymentCache = deploymentManager.getProcessDefinitionCache();

        if (StringUtils.isNotBlank(definitionId)) {
    

            // 清除指定缓存
            deploymentCache.remove(definitionId);

        } else {
    

            // 清除全部缓存
            deploymentCache.clear();

        }

        return null;

    }

}dContextUtil.getProcessEngineConfiguration().getDeploymentManager();

        DeploymentCache<ProcessDefinitionCacheEntry> deploymentCache = deploymentManager.getProcessDefinitionCache();
        deploymentCache.remove(definitionId);

        return null;
        
    }
    
}

其中 StringUtils 参考

package indi.tudan.common.core.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串处理工具类
 *
 * @author wangtan
 * @date 2019-10-27 13:43:20
 * @since 1.0.0
 */
public class StringUtils {
    

    /**
     * Don't let anyone else instantiate this class
     */
    private StringUtils() {
    
    }

    /**
     * 获取字符串
     *
     * @param object 待处理数据
     * @return 处理后的字符串
     * @date 2019-10-26 17:31:49
     */
    public static String getStr(Object object) {
    
        if (ObjectUtils.isNotNull(object)) {
    
            return String.valueOf(object);
        } else {
    
            return "";
        }
    }

    /**
     * 字符串是否为空
     *
     * @param cs 字符串
     * @return boolean
     * @date 2019-10-26 17:31:14
     */
    public static boolean isBlank(CharSequence cs) {
    
        int strLen;
        if (cs != null && (strLen = cs.length()) != 0) {
    
            for (int i = 0; i < strLen; ++i) {
    
                if (!Character.isWhitespace(cs.charAt(i))) {
    
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 字符串是否不为空
     *
     * @param cs 字符串
     * @return boolean
     * @date 2019-10-26 17:31:07
     */
    public static boolean isNotBlank(CharSequence cs) {
    
        return !isBlank(cs);
    }

    /**
     * 若字符串为空,则返回 defaultString
     *
     * @param string        字符串
     * @param defaultString 默认字符串
     * @return String
     * @author wangtan
     * @date 2019-09-06 13:53:42
     * @since 1.0.0
     */
    public static String orElse(String string, String defaultString) {
    
        return isBlank(string) ? defaultString : string;
    }

    /**
     * 去除所有空白符
     *
     * @param str 字符串
     * @return
     * @date 2020-07-21 19:55:39
     * @since 1.0.0
     */
    public static String replaceBlank(String str) {
    
        String dest = null;
        if (str == null) {
    
            return dest;
        } else {
    
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
            return dest;
        }
    }

}

二、如何调用

@Autowired
protected ManagementService managementService;

// 清除某个流程的缓存
// 此处的 xxxxxxxxxxxx 只是示例,请根据实际传流程定义Id
managementService.executeCommand(new DeploymentCacheCmd("xxxxxxxxxxxx"));

// 清除全部缓存
managementService.executeCommand(new DeploymentCacheCmd(""));

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/WTUDAN/article/details/117667837

智能推荐

ES6笔记--深度克隆(深拷贝和浅拷贝)_ed6深克隆-程序员宅基地

文章浏览阅读1.6k次。深度克隆(深拷贝和浅拷贝)拷贝数据:基本数据类型:拷贝后会生成一份新的数据,修改拷贝以后的数据不会影响原数据对象/数组拷贝后不会生成新的数据,而是拷贝引用,修改拷贝后的数据会影响原数据拷贝数据的方法:1.直接赋值给一个变量:浅拷贝 修改拷贝以后的数据会影响原数据2.Object.assign():浅拷贝3.Array.prototype.concat():浅拷贝,可用于合并数组,如果传值。4.Array.prototype.slice(startindex,endindex):浅拷贝5._ed6深克隆

C++ primer -IO库-fstream-程序员宅基地

文章浏览阅读277次,点赞7次,收藏8次。每次写操作前,均定位到文件末尾,不会截断文件,需要将内容添加到文件末尾时,应添加该模式,例:ofstrm.open("文件名", ofstream::app) 或 ofstrm.open("文件名", ofstream::out | ofstream::app)对于fstream和sstream,它们继承了iostream,因此接口支持iostream时,也支持使用fstream和sstream。以上是处理char字符的类型,对于宽字符类型,有wfstream/wifstream/wofstream。

机械优化设计进退法c语言程序,机械优化设计c语言程序讲解.doc-程序员宅基地

文章浏览阅读64次。计算 f(x1,x2)=x^2+x1^2-x0*x1-10*x0-4*x1+60#include "stdio.h"#include "stdlib.h"#include "math.h"double objf(double x[]){double ff;ff=x[0]*x[0]+x[1]*x[1]-x[0]*x[1]-10*x[0]-4*x[1]+60;return(ff);}void jtf(..._机械优化设计进退法c语言程序

Vue3打印插件Print.js的使用_vue3 print-js-程序员宅基地

文章浏览阅读1.8k次,点赞18次,收藏25次。如何认识和快速上手 `Print.js`,我们可以从官网的内容开始阅读,在官网中有很详细的介绍和使用例子,虽然是英文版的。`Print.js` 打印插件包括了 `PDF` 打印、`HTML` 打印、`JSON` 打印、图像打印等。本人每篇文章都是一字一句码出来,希望对大家有所帮助,多提提意见。_vue3 print-js

YOLOV8 C++ opecv_dnn模块部署_opencv4.7 cudnn yolov8-程序员宅基地

YOLOV8 C++ opecv_dnn模块部署。opencv编译需时间久,GPU版本可实时,有问题私信留言。

JS获得token_js获取token-程序员宅基地

文章浏览阅读2.3w次。使用struts有一个很奇怪的事情,就是你不知道在什么时候,就放进来一个bug,重复地提交,而且渗透到好几个方法,甚至整个action都会被污染。像打补丁似的,struts本身可以有一个可以用来防止重复提交的拦截器: 虽然这个token能够有效地防止重复提交,但是也能够让你原来的架构一团糟。可以拿一个亲身经历作为教材。在一个搭了frame的框架里,左边的frame_js获取token

随便推点

Xshell如何上传文件_如何使用xshell上传文件-程序员宅基地

文章浏览阅读153次。/ 上传文件,单机选中上传的文件。_如何使用xshell上传文件

xml报文转Java实体_xml字符串转换为实体对象-程序员宅基地

文章浏览阅读1.4k次。因为需要对接一些比较老的系统接口,他们的请求方式不是JSON数据结构,一般会采用xml数据结构来作为数据的入参和返参。因为我们的系统是通过JSON数据进行交互的突然接入xml数据结构的会比较的麻烦,麻烦的体现在xml数据结构比较复杂,同时如果采用字符串拼接的话会比较的难以维护。通过JAXBContext来将xml字符串转为Java实体或者把Java实体转为xml字符串_xml字符串转换为实体对象

关于形如--error LNK2005: xxx 已经在 msvcrtd.lib ( MSVCR90D.dll ) 中定义--的问题分析解决_error lnk2005: __lock 已经在 msvcrtd.lib(msvcr120d.dl-程序员宅基地

文章浏览阅读604次。http://www.cnblogs.com/qinfengxiaoyue/archive/2013/02/01/2889668.html--原文1.问题引出很久没有写程序设计入门知识的相关文章了,这篇文章要来谈谈程序库 (Library) 链接,以及关于 MSVC 与 CRT 之间的种种恩怨情仇。如果你使用的操作系统是 Linux、Mac 或其他非 Windo_error lnk2005: __lock 已经在 msvcrtd.lib(msvcr120d.dll) 中定义

org.springframework.beans.factory.BeanCreationException: Error creating bean...-程序员宅基地

文章浏览阅读527次。报错信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initService' defined in file [E:\WebWork\SMS\WebRoot\WEB-INF\classes\applicationContext-service.xml]: I..._rg.springframework.beans.factory.beancreationexception: error creating bean

JavaScript版本一览_javascript的版本是写在拿的-程序员宅基地

文章浏览阅读1.5k次。JavaScript 1.0这是JavaScript的第一个发布版本,由Brendan Eich开发,并在1996年3月伴随Netscape公司的Navigator 2.0一起发布。JavaScript 1.1这个版本包含在1996年8月发布的Netscape Navigator 3.0中。ECMA-262第一版就是以这个版本为基础编写的。JavaScript 1.2Netscape Naviga_javascript的版本是写在拿的

oracle忘记密码_oracle密码忘记了-程序员宅基地

文章浏览阅读1.9k次。打开一个终端窗口(cmd),输入以下命令进入SQL*Plus。3、查看用户(知道要修改用户名的跳过)_oracle密码忘记了