AsyncTask返回封装与数据缓存
public class DataStructure {
public static final class StInfo<T> {
public boolean success;
public T data;
public int code;
public String errMsg;
public StInfo<T> success(T data) {
this.success = true;
this.data = data;
return this;
}
public StInfo<T> fail(String reason) {
return fail(reason, -1);
}
public StInfo<T> fail(String reason, int code) {
this.success = false;
this.errMsg = reason;
this.code = code;
return this;
}
}
public static final class MemoryCacheItem<T> {
public T data;
public long cacheTime;
public MemoryCacheItem<T> cache(T data) {
this.data = data;
this.cacheTime = new Date().getTime();
return this;
}
public boolean isExpired() {
return data == null || new Date().getTime() - cacheTime >= 5 * 60 * 1000;
}
}
}