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

com.alicp.jetcache.CacheLoader Maven / Gradle / Ivy

The newest version!
package com.alicp.jetcache;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

/**
 * Created on 2017/5/27.
 *
 * @author huangli
 */
@FunctionalInterface
public interface CacheLoader extends Function {
    V load(K key) throws Throwable;

    default Map loadAll(Set keys) throws Throwable {
        Map map = new HashMap<>();
        for (K k : keys) {
            map.put(k, load(k));
        }
        return map;
    }

    @Override
    default V apply(K key) {
        try {
            return load(key);
        } catch (Throwable e){
            throw new CacheInvokeException(e.getMessage(), e);
        }
    }

    default boolean vetoCacheUpdate() {
        return false;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy