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

import com.fs.hisStore.domain.FsUserScrm;
import com.fs.hisStore.service.IFsUserScrmService;
import com.fs.hisStore.service.cache.IFsUserCacheService;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
@Slf4j
@RequiredArgsConstructor
public class IFsUserCacheScrmServiceImpl implements IFsUserCacheService {
    private final IFsUserScrmService fsUserService;

    private static final Cache<Long, FsUserScrm> FS_USER_CACHE = Caffeine.newBuilder()
            .maximumSize(1000)
            .expireAfterWrite(3, TimeUnit.MINUTES)
            .build();

    @Override
    public FsUserScrm selectFsUserById(Long userId) {
        return FS_USER_CACHE.get(userId,e-> fsUserService.selectFsUserById(userId));
    }
}
