com.playtika.shepherd.inernal.utils.CacheUtils Maven / Gradle / Ivy
package com.playtika.shepherd.inernal.utils;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
public class CacheUtils {
public static Supplier memoize(Supplier delegate) {
AtomicReference value = new AtomicReference<>();
return () -> {
T val = value.get();
if (val == null) {
val = value.updateAndGet(cur -> cur == null ?
Objects.requireNonNull(delegate.get()) : cur);
}
return val;
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy