blob: fbada678aaf0819676e160c74c3fe940fc492ffa [file] [log] [blame]
package org.apache.freemarker.generator.base.util;
import java.util.function.Supplier;
public class CachingSupplier<T> implements Supplier<T> {
private T cachedValue;
private final Supplier<T> supplier;
public CachingSupplier(Supplier<T> supplier) {
this.supplier = supplier;
}
@Override
public synchronized T get() {
if (cachedValue == null) {
cachedValue = supplier.get();
}
return cachedValue;
}
}