All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.playtika.shepherd.inernal.utils.CacheUtils Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
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