Java Cache
Пример guava кашерировани
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import org.junit.Test; import java.util.concurrent.TimeUnit; public class TestCode { @Test public void testName() throws Exception { LoadingCache<String, String> graphs = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.MINUTES).build(new CacheLoader<String, String>() { @Override public String load(String key) throws Exception { System.out.println("call load"); return "new body"; } }); graphs.put("someKey1", "Hello World"); System.out.println(graphs.get("someKey1")); System.out.println(graphs.get("someKey")); System.out.println(graphs.get("someKey")); } }