package com.muyu;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.concurrent.TimeUnit;

@SpringBootTest
class IotDbApplicationTests {

    @Test
    void contextLoads() throws InterruptedException {
        Cache<String, String> built = Caffeine.newBuilder()
                .initialCapacity(5)
                .maximumSize(10)
                //过期时间3秒钟
                .expireAfterWrite(3, TimeUnit.SECONDS)
                .build();



//        //写入缓存数据
//        built.put("userName","张三");
//
//        //读取缓存数据
//        String string = built.get("userName", (key) -> {
//            return "key已过期";
//        });
//
//        System.out.println("第一次查询结果:"+string);
//        Thread.sleep(4000);
//
//        //读取量
//        String name = built.get("userName", (key) -> {
//            return "key已过期";
//        });
//        System.out.println("第二次查询结果:"+name);



    }

}
