package cc.smtweb.framework.core.mvc.service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Akmm at 2022/3/3 11:13
 * 数据提供者，线程级缓存
 */
public class AbstractCompProvider {
    //临时缓存
    private Map<String, Object> cacheData = new HashMap<>();

    protected <T> T doGetData(String key, IDataProvider<T> loader) {
        cacheData.computeIfAbsent(key, s -> loader.load());
        if (!cacheData.containsKey(key)) {
            cacheData.put(key, loader.load());
        }
        return (T) cacheData.get(key);
    }
}
