Monthly Archives: September 2015

Using Java 8 Lambdas with Google Guava Caches

With Guava, you can define a simple in-memory cache with import static java.util.concurrent.TimeUnit.DAYS; import; import; Cache cache = CacheBuilder.newBuilder() .maximumSize(100000) .expireAfterAccess(7, DAYS) .build(); With this you can use .put(K, V) to load values, and .getIfPresent(K), which returns null if the key isn’t present. Sometimes it’s more convenientĀ to use get(K key, Callable<? extends V> […]