
com.github.houbb.heaven.support.cache.impl.AbstractCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of heaven Show documentation
Show all versions of heaven Show documentation
Collect base useful tools for dev.
The newest version!
package com.github.houbb.heaven.support.cache.impl;
import com.github.houbb.heaven.support.cache.ICache;
import com.github.houbb.heaven.util.lang.ObjectUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 抽象 cache 实现
* @author binbin.hou
* @since 0.1.63
*/
public abstract class AbstractCache implements ICache {
/**
* cache 实例
* @since 0.1.63
*/
private final Map cache = new ConcurrentHashMap<>();
/**
* 构建值
* @param key key
* @return 结果
* @since 0.1.63
*/
protected abstract V buildValue(final K key);
@Override
public V get(K key) {
V result = cache.get(key);
if(ObjectUtil.isNotNull(result)) {
return result;
}
// 构建
result = buildValue(key);
// 设置
set(key, result);
return result;
}
@Override
public void set(K key, V value) {
cache.put(key, value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy