java.lang.Object
org.miaixz.bus.cache.metric.CaffeineCache<K,V>
- Type Parameters:
K- 键类型V- 值类型
- All Implemented Interfaces:
CacheX<K,V>
Caffeine 缓存支持
基于Caffeine实现的高性能本地缓存,提供接近最优的命中率。 支持设置最大容量、过期时间等配置参数,并提供批量读写操作。
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionCaffeineCache(long size, long expire) 构造函数CaffeineCache(long size, long expire, com.github.benmanes.caffeine.cache.CacheLoader<K, V> cacheLoader) 构造函数(支持异步加载)CaffeineCache(Properties properties) 构造方法 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()清空缓存long获取缓存估算大小获取内部缓存实例(用于高级操作)getStats()获取缓存统计信息read(Collection<K> keys) 从缓存中批量读取值从缓存中读取单个值void从缓存中移除指定的键void向缓存中批量写入键值对void向缓存中写入单个键值对Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.cache.CacheX
containsKey, write
-
Constructor Details
-
CaffeineCache
public CaffeineCache(long size, long expire) 构造函数使用指定的大小和过期时间创建缓存实例
- Parameters:
size- 最大缓存条目数expire- 过期时间(毫秒)
-
CaffeineCache
构造方法使用Properties配置创建缓存实例,支持配置最大容量、过期时间等参数
- Parameters:
properties- 配置属性
-
CaffeineCache
public CaffeineCache(long size, long expire, com.github.benmanes.caffeine.cache.CacheLoader<K, V> cacheLoader) 构造函数(支持异步加载)使用指定的大小、过期时间和缓存加载器创建缓存实例
- Parameters:
size- 最大缓存条目数expire- 过期时间(毫秒)cacheLoader- 缓存加载器
-
-
Method Details
-
read
从缓存中读取单个值 -
read
从缓存中批量读取值 -
write
向缓存中写入单个键值对 -
write
向缓存中批量写入键值对 -
remove
从缓存中移除指定的键 -
clear
public void clear()清空缓存 -
getStats
获取缓存统计信息- Returns:
- 缓存统计信息
-
estimatedSize
public long estimatedSize()获取缓存估算大小- Returns:
- 缓存估算大小
-
getNativeCache
获取内部缓存实例(用于高级操作)- Returns:
- 内部缓存实例
-