Distributed caching

The below document mentions that Process Definitions are cached in Camunda: Process Definition Cache | docs.camunda.org

Is this a local cache used ? What happens in case of a distributed set up. Can the Process definition cache be configured to be a distributed cache ?

1 Like

@Rhalsnad, Deployment Cache (in memory) was introduced to avoid polling the database every time a process definition is needed.

Reference: Deployment Cache | docs.camunda.org

You can customize the maximum Capacity of the Cache like below:

<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
	<!-- Your property definitions! -->
	....					
	<property name="cacheCapacity" value="120" />  
</bean>

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.

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

  • Process definition
  • Case definition
  • Decision definition
  • Decision requirements definition

Provide a custom Cache Implementation by implementing the Cache interface from org.camunda.util.commons package and then plug in you cache implementation into a custom CacheFactory

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

public class MyCacheFactory extends CacheFactory {

  @Override
  public <T> Cache<String, T> createCache(int maxNumberOfElementsInCache) {
    return new MyCacheImplementation<String, T>(maxNumberOfElementsInCache);
  }
}

Custom cache factory configuration:

<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
	<!-- Your property definitions! -->
					....

	<property name="cacheFactory">
			<bean class="org.camunda.bpm.engine.test.api.cfg.MyCacheFactory" />
	</property>
</bean>

Package: org.camunda.commons.utils.cache
Interface: Cache.java

<dependency>
    <groupId>org.camunda.commons</groupId>
    <artifactId>camunda-commons-utils</artifactId>
    <version>1.9.0</version>
</dependency>

@Rhalsnad,

The current solution works in a distributed setup as well. All engines of a cluster use the same database and in case of a cache miss on one of the cluster members, the process definition is saved in the other local cache, too.

Hope this helps, Ingo