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

org.rx.core.MemoryCache Maven / Gradle / Ivy

package org.rx.core;

import org.rx.util.function.BiFunc;

import java.util.*;

import static org.rx.core.Contract.NonWarning;
import static org.rx.core.Contract.require;

public interface MemoryCache {
    static  TV getOrStore(TK key, BiFunc supplier) {
        return getOrStore(key, supplier, CacheKind.WeakCache);
    }

    static  TV getOrStore(TK key, BiFunc supplier, CacheKind kind) {
        require(key, supplier, kind);

        return MemoryCache.getInstance(kind).get(key, supplier);
    }

    @SuppressWarnings(NonWarning)
    static  MemoryCache getInstance(CacheKind kind) {
        switch (kind) {
            case ThreadCache:
                return ThreadCache.getInstance();
            case LruCache:
                return Internal.LazyCache.getValue();
            case SoftCache:
                return Internal.SoftCache;
            default:
                return Internal.WeakCache;
        }
    }

    int size();

    Set keySet();

    void add(TK key, TV val);

    default void remove(TK key) {
        remove(key, true);
    }

    void remove(TK key, boolean destroy);

    void clear();

    TV get(TK key);

    TV get(TK key, BiFunc supplier);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy