Here you can find the source of getExpiringMap(long time, TimeUnit unit)
public static <T, V> LoadingCache<T, V> getExpiringMap(long time, TimeUnit unit)
//package com.java2s; //License from project: Open Source License import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import java.util.concurrent.TimeUnit; public class Main { public static <T, V> LoadingCache<T, V> getExpiringMap(long time, TimeUnit unit) { return (LoadingCache<T, V>) CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(time, unit) .build(new CacheLoader() { public Object load(Object key) { throw new RuntimeException(); }//w ww .j ava 2 s.c om }); } }