package com.usky.rule.cache;

import com.usky.rule.vo.trigger.DeviceTrigger;
import com.usky.rule.vo.trigger.SpaceTrigger;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.cache2k.Cache;
import org.cache2k.Cache2kBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RuleEngineCache {
    public RuleEngineCache() {
    }

    @Bean(
            name = {"consumptionTriggerCache"}
    )
    public Cache<Long, List<DeviceTrigger>> consumptionTriggerCache() {
        return (new Cache2kBuilder<Long, List<DeviceTrigger>>() {
        }).name("consumptionTriggerCache").eternal(true).entryCapacity(100000L).build();
    }

    @Bean(
            name = {"spaceTriggerCache"}
    )
    public Cache<Long, List<SpaceTrigger>> spaceTriggerCache() {
        return (new Cache2kBuilder<Long, List<SpaceTrigger>>() {
        }).name("spaceTriggerCache").eternal(false).expireAfterWrite(1L, TimeUnit.HOURS).entryCapacity(100000L).build();
    }
}
