Issue
-
When using a custom MultiVM cache in a clustered Liferay DXP environment, entries are not replicating across all nodes.
-
Updates made to the cache on one node are not visible on other nodes, as the cache entries are only being stored locally.
Environment
-
Liferay DXP 2023.Q1+
-
Clustered Environment
Resolution
By default, Liferay's clustered cache mechanism is configured for invalidation rather than replication to optimize performance. This means when a cache entry is updated on one node, other nodes receive a message to remove (invalidate) their local copy of that entry. The data is then re-fetched from the original source on the next request. To change this behavior to direct replication, where the updated object is copied to all other nodes in the cluster, follow these steps:
- Ensure that clustering is enabled in your
portal-ext.propertiesfile:cluster.link.enabled=true - Add the following property to your
portal-ext.propertiesfile to enable direct copy replication for your custom cache (replace[CACHE_NAME]with your actual cache name):ehcache.replicator.properties.[CACHE_NAME]=replicatePutsViaCopy=true,replicateUpdatesViaCopy=true
Setting the replicatePutsViaCopy and replicateUpdatesViaCopy properties to true ensures that both new entries and updates are propagated with their full values to all nodes in the cluster.
Additional Information
It is recommended to apply this configuration in the portal-ext.properties file rather than in a module-multi-vm.xml file. Future versions of Liferay DXP (2025.x and later) migrate to Ehcache 3.x, which introduces changes to cache configuration. Using portal-ext.properties is a more forward-compatible approach.