In previous versions of WSO2 Governance Registry, cache invalidation was only possible within a single cluster domain. From G-Reg 5.0.0 onwards, cache invalidation is possible within different cluster domains. Since different products cannot be included in a single cluster domain, the caching data passes from one product cluster to another. For information on how to set up a cluster, see Setting up a Cluster.
The approach is to create a message broker and from each cluster, one node (coordinator) is registered to the broker. When one node gets an update, the broker is notified and the other clusters are notified by the broker to update their cache. First, you need to install the global cache invalidation feature.
You can write a custom notification implementation to support different message broker protocols. The default implementation is the JMS protocol.
Cache invalidation only works after enabling the configuration in the
cache.properties file. Make sure that the feature is installed in the server via the feature management console. The feature can be enabled by adding the following settings to the
cache.properties file located in the
enabled - This is to enable and disable global cache invalidation.
class.CacheInvalidationClass - The invalidation class to be used for the invalidation notification. It consists of setting up connection, subscribing and publishing implementation.
- cacheInvalidationTopic - The topic name of the cache invalidation broker.
Configure with ActiveMQ
Follow the instructions below to setup and configure with ActiveMQ.
- Download and setup Apache ActiveMQ. Please note that ActiveMQ should be up and running before starting WSO2 G-Reg.
- Copy the following client libraries from the
<AMQ_HOME>/libdirectory to the
For ActiveMQ 5.8.0 and above:
For earlier versions of ActiveMQ:
cache.propertiesfile in the
<GREG_HOME>/repository/confdirectory as follows,
For developers who wants to invalidate the global cache among clusters,
- Get the registered
org.wso2.carbon.caching.impl.CacheInvalidatorOSGi service and check the existence of the service.
- Call the
invalidateCache(int tenantId, String cacheManagerName, String cacheName, Serializable cacheKey)method.
- Set the tenant ID, cache manager name, cache name and serializable key in the relevant places in the code that need to invalidate the cache.
An example of referencing the registered CacheInvalidator service can be found under the following component: https://github.com/wso2/carbon-kernel/tree/v4.4.1/core/org.wso2.carbon.registry.core
For more information about building OSGi bundles, see this tutorial in the WSO2 Library: http://wso2.com/library/tutorials/develop-osgi-bundles-using-maven-bundle-plugin/