package thyyxxk.webserver.service.hutoolcache;

import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import org.springframework.stereotype.Component;
import thyyxxk.webserver.entity.dictionary.pathwayTemplates.vo.TemplateDayVo;

import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

@Component
public class ClinicalPathwayCache implements HutoolCacheInterface<List<TemplateDayVo>> {
    private static final int CACHE_SIZE = 32;
    Cache<String, List<TemplateDayVo>> cache = CacheUtil.newLFUCache(CACHE_SIZE);

    @Override
    public void put(String key, List<TemplateDayVo> value) {
        cache.put(key, value);
    }

    @Override
    public List<TemplateDayVo> get(String key) {
        return null;
    }

    public List<TemplateDayVo> getTemplateDayNotContent(String templateId, Supplier<List<TemplateDayVo>> supplier) {
        List<TemplateDayVo> data = supplier.get();
        put(templateId, data);
        return data;
    }

    @Override
    public void del(String key) {
        cache.remove(key);
    }

    @Override
    public void clear() {
        cache.clear();
    }

    @Override
    public List<CacheAll> getAll() {
        return this.getAllUtils(cache.cacheObjIterator());
    }

    @Override
    public String getLabel() {
        return "临床路径";
    }
}
