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

com.github.phantomthief.util.CacheBasedDataAccess Maven / Gradle / Ivy

The newest version!
/**
 * 
 */
package com.github.phantomthief.util;

import java.util.Collection;
import java.util.Map;

import com.google.common.cache.Cache;

/**
 * @author w.vela
 */
public class CacheBasedDataAccess implements IMultiDataAccess {

    private final Cache cache;

    private CacheBasedDataAccess(Cache cache) {
        this.cache = cache;
    }

    public static  IMultiDataAccess of(Cache cache) {
        return new CacheBasedDataAccess<>(cache);
    }

    @Override
    public Map get(Collection keys) {
        return cache.getAllPresent(keys);
    }

    @Override
    public void set(Map dataMap) {
        if (dataMap != null) {
            dataMap.entrySet().stream()
                    .filter(entry -> entry.getKey() != null && entry.getValue() != null)
                    .forEach(entry -> cache.put(entry.getKey(), entry.getValue()));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy