package com.fs.course.service.cache.impl;

import com.fs.course.domain.FsCourseQuestionBank;
import com.fs.course.domain.FsUserCourseVideo;
import com.fs.course.service.IFsCourseQuestionBankService;
import com.fs.course.service.cache.IFsCourseQuestionBankCacheService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class FsUserCourseQuestionBankCacheServiceImpl implements IFsCourseQuestionBankCacheService {

    private static final Cache<Long, String> CATEGORY_CACHE = Caffeine.newBuilder()
            .maximumSize(1000)
            .expireAfterWrite(3, TimeUnit.HOURS)
            .build();

    @Autowired
    private IFsCourseQuestionBankService fsCourseQuestionBankService;


    @Override
    public String selectFsUserCourseCategoryByCateId(Long cateId) {
        return CATEGORY_CACHE.get(cateId,e->{
            String cateName = fsCourseQuestionBankService.selectNameByCateId(cateId);
            if(cateName == null) {
                return "";
            }
            return cateName;
        });
    }
}
