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

import com.fs.company.domain.CompanyUser;
import com.fs.course.domain.FsUserCourseVideo;
import com.fs.course.service.IFsCourseAnswerLogsService;
import com.fs.course.service.IFsUserCourseVideoService;
import com.fs.course.service.cache.IFsUserCourseVideoCacheService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@AllArgsConstructor
@Service
@Slf4j
public class FsUserCourseVideoCacheServiceImpl implements IFsUserCourseVideoCacheService {

    private final IFsUserCourseVideoService fsUserCourseVideoService;
    private static final Cache<Long, FsUserCourseVideo> VIDEO_CACHE = Caffeine.newBuilder()
            .maximumSize(1000)
            .expireAfterWrite(3, TimeUnit.MINUTES)
            .build();

    @Override
    public FsUserCourseVideo selectFsUserCourseVideoByVideoId(Long videoId) {
        return VIDEO_CACHE.get(videoId,e-> fsUserCourseVideoService.selectFsUserCourseVideoByVideoId(videoId));
    }
}
