All process definitions are cached (after they have been parsed) to avoid polling the database every time a process definition is needed and because process definition data doesn’t change. This reduces the latency of referencing the process definitions and thus improves the performance of the system.

Customize the maximum Capacity of the Cache

If one has many process definitions, the cache might occupy a large amount of memory and the capacity of the working memory may reach its limits. Therefore, after the maximum capacity is reached the least recently used process definition entry is evicted from the cache to satisfy the capacity condition. However, if one still meets out of memory issues, it can be necessary to lower the maximum capacity of the cache.

By changing the maximum capacity, the configuration effects all of the following cache components:

  • Process definition
  • Case definition
  • Decision definition
  • Decision requirements definition
    In the process engine configuration one can specify the maximum capacity of the cache. The default value is 1000. When the process engine is created, this property will be set and all resources will be scanned and deployed accordingly. As an example the maximum capacity could be set to 120 as follows:
  1. <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
  2. <!-- Your property definitions! -->
  3. ....
  4. <property name="cacheCapacity" value="120" />
  5. </bean>

Note: The same capacity is used for all of the components stated above and it is not possible to set the capacity size individually for each component. Furthermore, in the default cache implementation corresponds the capacity size to the maximum number of elements in the cache that are used. That means, the absolute amount of physical storage (e.g. mega bytes) you use up depends on the size needed for the respective process definitions.

Provide a custom Cache Implementation

The default implementation of the cache evicts the least recently used entry as soon as the maximum capacity is exceeded. If it is necessary to choose the evicted cache entries by a different criteria, one can provide its own cache implementation.

One can do this by implementing the Cache interface from org.camunda.util.commons package. Let’s assume for example that the following class has been implemented:

  1. public class MyCacheImplementation<K, V> implements Cache<K, V> {
  2. // implement interface methods and your own cache logic here
  3. }

Next, one need to plug in MyCacheImplementation into a custom CacheFactory:

  1. public class MyCacheFactory extends CacheFactory {
  2. @Override
  3. public <T> Cache<String, T> createCache(int maxNumberOfElementsInCache) {
  4. return new MyCacheImplementation<String, T>(maxNumberOfElementsInCache);
  5. }
  6. }

The factory is used to provide the cache implementation for different cache components such as the process definition or the case definition. Once this is done, one can use the process engine configuration where one can specify a set of resources. When the process engine is created, all those resources will be scanned and deployed. In the given example the custom cache factory could now be deployed as follows:

  1. <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
  2. <!-- Your property definitions! -->
  3. ....
  4. <property name="cacheFactory">
  5. <bean class="org.camunda.bpm.engine.test.api.cfg.MyCacheFactory" />
  6. </property>
  7. </bean>

原文: https://docs.camunda.org/manual/7.9/user-guide/process-engine/deployment-cache/