Caching and messaging

Caffeine.expireAfterWrite

Expire relative to creation or most recent replacement. Source-reviewed integration fragment or manual procedure, NOT RUN.

Formal Syntax & Structure

java syntaxjava
expireAfterWrite(Duration.ofSeconds(30))

Working Example

Example Snippetjava
import com.github.benmanes.caffeine.cache.Cache;import com.github.benmanes.caffeine.cache.Caffeine;import java.time.Duration;public class CaffeineExample {    public static void main(String[] args) {        Cache<String, Integer> cache = Caffeine.newBuilder()            .maximumSize(100).expireAfterWrite(Duration.ofSeconds(30)).build();        System.out.println(cache.get("tenant-a:B1", k -> 5));        cache.invalidate("tenant-a:B1");        System.out.println(cache.getIfPresent("tenant-a:B1"));    }}
Java Reference