flowable自定义流程定义缓存

时间:2019-09-06
本文章向大家介绍flowable自定义流程定义缓存,主要包括flowable自定义流程定义缓存使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

场景:当大量的流程定义出现的时候,我们势必会不停的查询流程定义,然而流程定义之后和版本对应很少发生变化,这个时候,我们可以把这个流程定义缓存起来,以提高系统性能。

这里我采用的是ehcache作为缓存

1、定义流程定义缓存对象

@Component
public class CustomDeploymentCache implements DeploymentCache<ProcessDefinitionCacheEntry> {
    @Autowired
    private CacheManager cacheManager;
    private Cache cache;

    public CustomDeploymentCache() {
        cache = cacheManager.getCache(CACHE_PROCESS_DEFINITION);
    }

    @Override
    public ProcessDefinitionCacheEntry get(String s) {
        return (ProcessDefinitionCacheEntry) cache.get(s);
    }

    @Override
    public boolean contains(String s) {
        boolean flag = false;
        if (cache.get(s) != null) {
            flag = true;
        }
        return flag;
    }

    @Override
    public void add(String s, ProcessDefinitionCacheEntry processDefinitionCacheEntry) {
        cache.put(s, processDefinitionCacheEntry);
    }

    @Override
    public void remove(String s) {
        cache.evict(s);
    }

    @Override
    public void clear() {
        cache.clear();
    }
}

2、配置缓存

//设置缓存
        configure.setProcessDefinitionCache(customDeploymentCache);

原文地址:https://www.cnblogs.com/liuwenjun/p/11474828.html