/** Look up the key in the downloads queue.
* @return True if it was found and we don't need to start the request. */
private boolean checkCache(ClientContext context) {
// Fproxy uses lookupInstant() with mustCopy = false. I.e. it can reuse stuff unsafely. If the user frees it it's their fault.
if(bogusUSK(context)) return false;
CacheFetchResult result = context.downloadCache == null ? null : context.downloadCache.lookupInstant(uri, !fctx.filterData, false, null);
if(result == null) return false;
Bucket data = null;
String mimeType = null;
if((!fctx.filterData) && (!result.alreadyFiltered)) {
if(fctx.overrideMIME == null || fctx.overrideMIME.equals(result.getMimeType())) {
// Works as-is.
// Any time we re-use old content we need to remove the tracker because it may not remain available.
tracker.removeFetcher(this);
onSuccess(result, null);
return true;
} else if(fctx.overrideMIME != null && !fctx.overrideMIME.equals(result.getMimeType())) {
// Change the MIME type.
tracker.removeFetcher(this);
onSuccess(new FetchResult(new ClientMetadata(fctx.overrideMIME), result.asBucket()), null);
return true;
}
} else if(result.alreadyFiltered) {
if(refilterPolicy == REFILTER_POLICY.RE_FETCH || !fctx.filterData) {
// Can't use it.
return false;
} else if(fctx.filterData) {
if(shouldAcceptCachedFilteredData(fctx, result)) {
if(refilterPolicy == REFILTER_POLICY.ACCEPT_OLD) {
tracker.removeFetcher(this);
onSuccess(result, null);
return true;
} // else re-filter
} else
return false;
} else {
return false;
}
}
data = result.asBucket();
mimeType = result.getMimeType();
if(mimeType == null || mimeType.equals("")) mimeType = DefaultMIMETypes.DEFAULT_MIME_TYPE;
if(fctx.overrideMIME != null && !result.alreadyFiltered)
mimeType = fctx.overrideMIME;
else if(fctx.overrideMIME != null && !mimeType.equals(fctx.overrideMIME)) {
// Doesn't work.