場景:當大量的流程定義出現的時候,我們勢必會不停的查詢流程定義,然而流程定義之后和版本對應很少發生變化,這個時候,我們可以把這個流程定義緩存起來,以提高系統性能。
這里我采用的是本地緩存
1、定義流程定義緩存對象
@Component
public class CustomDeploymentCache implements DeploymentCache<ProcessDefinitionCacheEntry> {
// @Autowired
// private CacheManager cacheManager;
public static final Map<String,ProcessDefinitionCacheEntry> caches = new ConcurrentHashMap<>();
@Override
public ProcessDefinitionCacheEntry get(String s) {
return caches.get(s);
}
@Override
public boolean contains(String s) {
boolean flag = false;
if (caches.get(s) != null) {
flag = true;
}
return flag;
}
@Override
public void add(String s, ProcessDefinitionCacheEntry processDefinitionCacheEntry) {
caches.put(s, processDefinitionCacheEntry);
}
@Override
public void remove(String s) {
caches.remove(s);
}
@Override
public void clear() {
caches.clear();
}
}
2、配置緩存
//設置緩存 configure.setProcessDefinitionCache(customDeploymentCache);