com.hecloud.runtime.database.cache.UpdateCache Maven / Gradle / Ivy
package com.hecloud.runtime.database.cache;
import java.util.LinkedHashMap;
import java.util.Optional;
/**
* 更新SQL语句缓存
*
* @author LoveinBJ
*/
public class UpdateCache extends LinkedHashMap {
/**
*
*/
private static final long serialVersionUID = 1L;
private int capacity = 16;
public UpdateCache(int capacity) {
super(16, 0.75f, true);
if (capacity > 0) {
this.capacity = capacity;
}
}
@Override
protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
return super.size() > capacity;
}
public synchronized void putCache(String key, String value) {
this.put(key, value);
}
public synchronized String getCache(String key) {
String value = this.get(key);
Optional.ofNullable(value).ifPresent(data -> this.put(key, data));
return value;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy