Configure a nonstop cache programmatically in Ehcache

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);
Advertisements

4 thoughts on “Configure a nonstop cache programmatically in Ehcache

    1. When using a clustered cache, you have a number of applications sharing the cache content in a cluster.
      If your application is temporarily disconnected from the cluster (for instance because of a network problem), you can set your cache as nonstop, meaning that it will continue working according to the nonstop behaviour you define, instead of being blocked.

      1. thanks for your sufficient explanation.
        but I have misunderstanding the point of ; what’s the “timeoutMillis” for? is that for making a time for blocking specific running operations in the cache ? .. and what’s the difference between it and ” timeToLiveSeconds”?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s