public class DateTimeUtils {
public static final LocalDate DEFAULT_DATE = LocalDate.of(2022, 1, 1);
public static final LocalTime DEFAULT_TIME = LocalTime.of(12, 0, 0);
public static LocalDate getDefaultDate() {
return DEFAULT_DATE;
}
public static LocalTime getDefaultTime() {
return DEFAULT_TIME;
}
}
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
public class DateTimeCache {
private static final Cache<String, LocalDateTime> CACHE = Caffeine.newBuilder()
.maximumSize(1000)
.build();
public static LocalDateTime getCachedDateTime(String key) {
LocalDateTime cachedDateTime = CACHE.getIfPresent(key);
if (cachedDateTime != null) {
return cachedDateTime;
} else {
LocalDateTime newDateTime = calculateDateTime(key);
CACHE.put(key, newDateTime);
return newDateTime;
}
}
private static LocalDateTime calculateDateTime(String key) {
// ...
}
}