![JAR search and dependency download from the Maven repository](/logo.png)
com.dxy.library.cache.memory.caffeine.CacheCaffeine Maven / Gradle / Ivy
package com.dxy.library.cache.memory.caffeine;
import com.dxy.library.cache.memory.IMemory;
import com.dxy.library.util.common.config.ConfigUtils;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.TimeUnit;
/**
* 基于caffeine的内存缓存器
* @author duanxinyuan
* 2018/8/8 19:48
*/
@Slf4j
public class CacheCaffeine implements IMemory {
private LoadingCache> cache;
public CacheCaffeine() {
cache = Caffeine.newBuilder()
.initialCapacity(NumberUtils.toInt(ConfigUtils.getConfig("cache.memory.key.capacity.initial"), 1000))
.maximumSize(NumberUtils.toInt(ConfigUtils.getConfig("cache.memory.key.capacity.max"), 5_0000))
.expireAfterWrite(NumberUtils.toInt(ConfigUtils.getConfig("cache.memory.expire.seconds.after.write"), 300), TimeUnit.SECONDS)
.expireAfterAccess(NumberUtils.toInt(ConfigUtils.getConfig("cache.memory.expire.seconds.after.access"), 300), TimeUnit.SECONDS)
.refreshAfterWrite(NumberUtils.toInt(ConfigUtils.getConfig("cache.memory.refresh.seconds.after.write"), 300), TimeUnit.SECONDS)
.recordStats()
.build(new CacheLoader>() {
@Nullable
@Override
public Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy