package gc.mda.kcg.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
@EnableCaching
public class CacheConfig {

    public static final String AIRCRAFT_IRAN = "aircraft-iran";
    public static final String AIRCRAFT_KOREA = "aircraft-korea";
    public static final String OSINT_IRAN = "osint-iran";
    public static final String OSINT_KOREA = "osint-korea";
    public static final String SATELLITES = "satellites";
    public static final String SEISMIC = "seismic";
    public static final String PRESSURE = "pressure";
    public static final String VESSEL_ANALYSIS = "vessel-analysis";

    @Bean
    public CacheManager cacheManager() {
        CaffeineCacheManager manager = new CaffeineCacheManager(
                AIRCRAFT_IRAN, AIRCRAFT_KOREA,
                OSINT_IRAN, OSINT_KOREA,
                SATELLITES,
                SEISMIC, PRESSURE,
                VESSEL_ANALYSIS
        );
        manager.setCaffeine(Caffeine.newBuilder()
                .expireAfterWrite(2, TimeUnit.DAYS)
                .maximumSize(1));
        return manager;
    }
}
