实际项目中常常需要用到本地缓存,特别是一些固定不变的数据,不想频繁调接口,因为http请求本身需要耗时,下面几个类对本地缓存作了简单实现,支持自动过期功能
LocalCache.javainterface LocalCache {
public void refresh();
}
LocalCacheItem.java/**
* 缓存项
* @author:
* @date: 2018年2月6日 下午6:01:33
*/
public class LocalCacheItem {
// 缓存时间:单位毫秒
private long cacheTime;
// 创建时间:单位毫秒
private long createTime;
// 缓存值
private Object value;
public LocalCacheItem() {
super();
}
public LocalCacheItem(long cacheTime, long createTime, Object value) {
super();
this.cacheTime = cacheTime;
this.createTime = createTime;
this.value = value;
}
public long getCacheTime() {
return cacheTime;
}
public void setCacheTime(long cacheTime) {
this.cacheTime = cacheTime;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
LocalCacheManage.javaimpo