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

import com.fs.his.domain.FsUser;
import com.fs.his.service.IFsUserService;
import com.fs.store.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 IFsUserCacheServiceImpl implements IFsUserCacheService {
    private final IFsUserService fsUserService;

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

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