Caffeine缓存增改查过期
1、引入pom
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.2</version>
</dependency>
2、测试类
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ReportApplication.class)
public class LocalCacheTest {
@Test
public void test() throws InterruptedException {
Cache<Object, String> cache1 = Caffeine.newBuilder()
.expireAfterWrite(1, TimeUnit.SECONDS)
.maximumSize(1000)
.build();
String key = "test";
cache1.put(key, "Okok10000");
System.out.println(cache1.getIfPresent(key));
System.out.println(cache1.getIfPresent(key));
cache1.put(key, "hello0");
System.out.println(cache1.getIfPresent(key));
Thread.sleep(1000);
System.out.println(cache1.getIfPresent(key));
}
}
缓存----》内存 缓存过期时间和是否需要用缓存想好了再用
最后
以上就是稳重大米最近收集整理的关于Caffeine缓存增改查过期的全部内容,更多相关Caffeine缓存增改查过期内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复