Tutorial Steps
Introduction- The Weather Application
- Initializing the CacheManager
- Putting stuff in the cache
- Making entries expire
- Configuring the cache
- Clustering the application
- Listen to changes in the cluster
- Listen to changes in the cache
- Grouping entries together
- Temperature averages with streams
- Declarative configuration
The Weather App
In the previous step we used the overloaded put() method to store mortal entries. But since we want all of our entries to expire with the same lifespan, we can configure the cache to have default expiration values. To do this we will customize the org.infinispan.configuration.cache.Configuration. A configuration in Infinispan is mostly immutable, aside from some runtime-tunable parameters, and is constructed by means of a ConfigurationBuilder. Using the above use-case, let's create a cache configuration where we want to set the default expiration of entries to 5 seconds. The following code shows how it's done:
cacheManager = new DefaultCacheManager();
ConfigurationBuilder config = new ConfigurationBuilder();
config.expiration().lifespan(5, TimeUnit.SECONDS);
cacheManager.defineConfiguration("weather", config.build());
The configuration builder uses a fluent pattern, so you can tune more configuration aspects with chained methods. With this in mind let's run our application again:
git checkout -f step-4
mvn clean package exec:exec
will yield the same result as we got in the previous step. We didn't change the behaviour of the application, we just changed the semantics of the cache.