-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathstep-4.html
40 lines (38 loc) · 2.28 KB
/
step-4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
layout: tutorial-extended
title: The Weather App
---
{% assign tutorial_github_url = "https://github.com/infinispan/infinispan-embedded-tutorial" %}
{% assign @tutorial_steps = "The Weather Application, Initializing the CacheManager, Putting stuff in the cache, Making entries expire, Configuring the default 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" | split: ", " %}
{% assign tutorial_step = 4 %}
<div class="grid-wrapper">
<div class="width-3-12 width-12-12-m">
{% include embedded-tutorial-menu.html tutorial_steps=tutorial_steps tutorial_step=tutorial_step %}
</div>
<div class="width-9-12 width-12-12-m">
<h4>{{page.title}}</h4>
<p>
In the previous step we used the overloaded <i>put()</i> 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 <i>org.infinispan.configuration.cache.Configuration.</i> A configuration in Infinispan is mostly immutable, aside from some runtime-tunable parameters, and is constructed by means of a <i>ConfigurationBuilder.</i> 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:
</p>
<pre>
<code class="java">
cacheManager = new DefaultCacheManager();
ConfigurationBuilder config = new ConfigurationBuilder();
config.expiration().lifespan(5, TimeUnit.SECONDS);
cacheManager.defineConfiguration("weather", config.build());
</code>
</pre>
<p>
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:
</p>
<pre>
<code class="nohighlight">
git checkout -f step-4
mvn clean package exec:exec
</code>
</pre>
<p>
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.
</p>
</div>
</div>