14.3.3.5. Configure Multiple Cache Managers with a Single Class


A single class can be used to configure multiple cache managers and remote cache managers based on the created qualifiers. An example of this is as follows:
public class Config {
	@Produces
	@ApplicationScoped
	public EmbeddedCacheManager
		defaultEmbeddedCacheManager() {
			Configuration cfg = new ConfigurationBuilder()
					.eviction()
					.strategy(EvictionStrategy.LRU)
					.maxEntries(150)
					.build();
			return new DefaultCacheManager(cfg);
		}

	@Produces
	@ApplicationScoped
	@DefaultClustered
	public EmbeddedCacheManager 
		defaultClusteredCacheManager() {
		GlobalConfiguration g = new GlobalConfigurationBuilder()
				.clusteredDefault()
				.transport()
				.clusterName("InfinispanCluster")
				.build();
		Configuration cfg = new ConfigurationBuilder()
				.eviction()
				.strategy(EvictionStrategy.LRU)
				.maxEntries(150)
				.build();
		return new DefaultCacheManager(g, cfg);
	}
	
	@Produces
	@ApplicationScoped
	@DefaultRemote
	public RemoteCacheManager
		defaultRemoteCacheManager() {
			return new RemoteCacheManager(ADDRESS, PORT);
		}

	@Produces
	@ApplicationScoped
	@RemoteCacheInDifferentDataCentre
	public RemoteCacheManager newRemoteCacheManager() {
		return new RemoteCacheManager(ADDRESS_FAR_AWAY, PORT);
	}
}
Copy to Clipboard Toggle word wrap
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat