Cache<Long, String> cache = Cache2kBuilder.of(Long.class, String.class)
.expireAfterWrite(Duration.ofMinutes(10))
.maximumSize(100)
.build();
cache.put(1L, "Hello");
String value = cache.get(1L);
Cache<Long, String> cache = Cache2kBuilder.of(Long.class, String.class)
.expireAfterWrite(Duration.ofMinutes(10))
.maximumSize(100)
.addListener((cache, entry) -> {
System.out.println("Item expired: " + entry.getKey());
})
.build();
Cache<Long, String> cache = Cache2kBuilder.of(Long.class, String.class)
.expireAfterWrite(Duration.ofMinutes(10))
.maximumSize(100)
.build();
cache.put(1L, "Hello");
String value = cache.get(1L);
cache.remove(1L);
CacheLoader<Long, String> loader = (key) -> {
return loadDataFromDatabase(key);
};
Cache<Long, String> cache = Cache2kBuilder.of(Long.class, String.class)
.expireAfterWrite(Duration.ofMinutes(10))
.maximumSize(100)
.loader(loader)
.build();
String value = cache.get(1L);