pro.chenggang.plugin.springcloud.gateway.offline.OfflineServerCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-cloud-gateway-plugin Show documentation
Show all versions of spring-cloud-gateway-plugin Show documentation
Spring Cloud Gateway Plugin Project
package pro.chenggang.plugin.springcloud.gateway.offline;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.concurrent.TimeUnit;
/**
* OfflineServerCache
* @author chenggang
* @date 2019/04/25
*/
public class OfflineServerCache {
public static Cache cache(){
return SingletonHandler.OFF_LINE_CACHE;
}
private static class SingletonHandler {
private static final Cache OFF_LINE_CACHE= CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.maximumSize(200)
.concurrencyLevel(Runtime.getRuntime().availableProcessors())
.build();
}
/**
* add offline server cache
* @param key
* @param status
*/
public static void addOfflineCache(String key, ServerOfflineStatus status){
OfflineServerCache.cache().put(key, status);
}
/**
* get offline cache
* @param key
* @return
*/
public static ServerOfflineStatus getOfflineCache(String key){
return OfflineServerCache.cache().getIfPresent(key);
}
}