com.nepxion.discovery.plugin.framework.cache.PluginCache Maven / Gradle / Ivy
package com.nepxion.discovery.plugin.framework.cache;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
public class PluginCache {
private LoadingCache loadingCache;
public PluginCache() {
loadingCache = Caffeine.newBuilder()
.expireAfterWrite(365 * 100, TimeUnit.DAYS)
.initialCapacity(10)
.maximumSize(100)
.recordStats()
.build(new CacheLoader() {
@Override
public String load(String key) throws Exception {
return StringUtils.EMPTY;
}
});
}
public boolean put(String key, String value) {
loadingCache.put(key, value);
return Boolean.TRUE;
}
public String get(String key) {
try {
return loadingCache.get(key);
} catch (Exception e) {
return StringUtils.EMPTY;
}
}
public boolean clear(String key) {
loadingCache.invalidate(key);
return Boolean.TRUE;
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy