static CacheManager workAroundCache95(CacheManager ehCacheManager) { final CacheConfiguration defaultConfig = ehCacheManager.getConfiguration().getDefaultCacheConfiguration(); final CacheConfiguration.CacheEventListenerFactoryConfiguration listenerConfig = new CacheConfiguration.CacheEventListenerFactoryConfiguration() .className(NoopCacheEventListenerFactory.class.getName()); defaultConfig.clone().addCacheEventListenerFactory(listenerConfig); if (defaultConfig.getCacheEventListenerConfigurations().isEmpty()) { LOG.warn("It looks like CACHE-95 has been fixed. This workaround should be removed."); } else { LOG.debug("Working around CACHE-95"); } return ehCacheManager; }
@Override @Nonnull public CacheConfiguration.CacheEventListenerFactoryConfiguration createCacheReplicatorConfiguration(final CacheSettings settings, final boolean selfLoadingCache) { final boolean replicateAsynchronously = settings.getReplicateAsynchronously(false); final boolean replicateViaCopy = settings.getReplicateViaCopy(false); // If the cache is self loading there is no need to replicate puts or updates as the loader takes care of // populating the cache as needed. // Else if the cache is replicating via copy then puts and updates should be replicated. // Else replicating puts is dangerous as it may lead to invalidations ping ponging between nodes. Whether to // replicate updates is ambiguous, but setting it may help to prevent stale caches while being less vulnerable // to the invalidation storm that comes with simply replicating puts. final boolean replicatePuts = !selfLoadingCache && replicateViaCopy; final boolean replicateUpdates = !selfLoadingCache; final String cacheProperties = String.format(CACHE_PROPERTIES, replicateAsynchronously, replicatePuts, replicateViaCopy, replicateUpdates, replicateViaCopy); return new CacheConfiguration.CacheEventListenerFactoryConfiguration() .className(RMICacheReplicatorFactory.class.getName()) .properties(cacheProperties); } }