Terracotta 10.7 | Ehcache API Developer Guide | Creating and Configuring a CacheManager Using Java | Data Freshness
 
Data Freshness
In Ehcache, data freshness is controlled through Expiry. The following example illustrates how to configure a time-to-live expiry.

CacheConfiguration<Long, String> cacheConfiguration =
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Long.class, String.class, ResourcePoolsBuilder.heap(100)) // <1>
.withExpiry(Expirations.timeToLiveExpiration( // <2>
Duration.of(20, TimeUnit.SECONDS)))
.build();
1. Expiry is configured at the cache level, so start by defining a cache configuration,
2. then add to it an Expiry, here using the predefined time-to-live one, configured with the required Duration.