Tôi cần thay đổi chiến lược lưu bộ nhớ cache mặc định thành chính sách "cache all" mà không tính đến tiêu đề HTTP.
Bạn muốn lưu vào bộ nhớ cache trong một khoảng thời gian đã định. Có một số cách bạn có thể làm điều này, vì có nhiều nơi trong mã "chạm" phản hồi mạng. Tôi đề xuất chỉnh sửa cho HttpHeaderParser
(parseCacheHeaders
phương pháp tại dòng 39):
Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
entry.ttl = now; // **Edited**
entry.serverDate = serverDate;
entry.responseHeaders = headers;
và một để Cache.Entry
lớp:
/** True if the entry is expired. */
public boolean isExpired() {
return this.ttl + GLOBAL_TTL < System.currentTimeMillis();
}
/** True if a refresh is needed from the original data source. */
public boolean refreshNeeded() {
return this.softTtl + GLOBAL_TTL < System.currentTimeMillis();
}
nơi GLOBAL_TTL
là một hằng số đại diện cho thời gian bạn muốn mỗi hình ảnh sống trong bộ nhớ cache.
Nguồn
2013-08-06 07:31:26