Infinispan Clustering
OpenMRS 2.8.x adds support for the embedded Infinispan cache in a clustered environment.
The cache in a clustered environment with multiple OpenMRS replicas needs to be replicated and/or invalidated in all replicas so the results are consistent on all nodes.
The Infinispan cache is used by Hibernate to provide 2nd level caching of individual entities so they do not have to be re-fetched and re-created from DB when referenced by id as well as for query caching to cache results of selected queries. See https://infinispan.org/docs/stable/titles/hibernate/hibernate.html#hibernate-cache
The Infinispan cache is also used by selected OpenMRS API methods to limit DB queries and processing of data for less often changing data in the system such as Concepts, Global Properties, etc. See https://infinispan.org/docs/stable/titles/spring/spring.html#spring-cache-provider
If you want to learn more on how to develop code and improve performance with caching, see Caching.
If you intend to run OpenMRS backend with multiple replicas you need to configure cache to run in a clustered mode with the following:
cache.type: "cluster"
cache.stack: "kubernetes"
jgroups.dns.query: 'openmrs-backend-headless.svc.cluster.local'
jgroups.bind.port: '7800'We support a number of stacks: tcp, kubernetes, google, tunnel, ec2, azure. Please visit Infinispan docs to learn more.
Please note that jgroups.bind.port sets the port for Hibernate cache. The port for OpenMRS API cache is plus one, which is 7801 in this case. You need to make sure that OpenMRS backend nodes can communicate on these 2 ports. The jgroups.dns.query needs to resolve to a list of IPs of OpenMRS backend nodes.