package org.jeecg.modules.adweb.gpt.cache;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.date.DateUnit;

import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

/**
 * 本地缓存 - {@link SseEmitter}
 *
 * @author chenrui
 * @date 2024/1/26 20:06
 */
public class SseEmitterCache {

    /** 缓存时长 */
    private static final long TIMEOUT = 5 * DateUnit.MINUTE.getMillis();

    /** 清理间隔 */
    private static final long CLEAN_TIMEOUT = 5 * DateUnit.MINUTE.getMillis();

    /** 缓存对象 */
    public static final TimedCache<String, SseEmitter> CACHE = CacheUtil.newTimedCache(TIMEOUT);

    static {
        // 启动定时任务
        CACHE.schedulePrune(CLEAN_TIMEOUT);
    }
}
