Over a million developers have joined DZone.
Silver Partner

Configure a Nonstop Cache Programmatically in Ehcache

· Java Zone

The Java Zone is brought to you in partnership with DCHQ.  Discover how to deploy & monitor multi-tier Java applications on any cloud in seconds.

Here’s how to configure programmatically a nonstop cache in Ehcache (this one is clustered, connecting to terracotta running on localhost):

import net.sf.ehcache.config.*;

Configuration configuration = new Configuration()
   .terracotta(new TerracottaClientConfiguration().url("localhost:9510"))
   .defaultCache(new CacheConfiguration("defaultCache", 10000))
   .cache(
      new CacheConfiguration("nonstopCache", 10000)
      .terracotta(new TerracottaConfiguration().consistency(TerracottaConfiguration.Consistency.STRONG)
      .nonstop(new NonstopConfiguration().enabled(true).timeoutMillis(4000)
      .timeoutBehavior(new TimeoutBehaviorConfiguration()
      .type(TimeoutBehaviorConfiguration.TimeoutBehaviorType.LOCAL_READS.getTypeName())))
   )
);
CacheManager cacheManager = new CacheManager(configuration);

The Java Zone is brought to you in partnership with DCHQ. Learn more about best practices for automating the deployment and management of your Java application on any cloud.

Topics:

Published at DZone with permission of Aurelien Broszniowski , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}