return copyToCache(location, fileStore, delegate.getResource(location));
}
// We might be able to use a cached/locally available version
if (cached != null && !externalResourceCachePolicy.mustRefreshExternalResource(getAgeMillis(timeProvider, cached))) {
return new DefaultLocallyAvailableExternalResource(location, new DefaultLocallyAvailableResource(cached.getCachedFile()), cached.getExternalResourceMetaData());
}
// Get the metadata first to see if it's there
final ExternalResourceMetaData remoteMetaData = delegate.getMetaData(location);
if (remoteMetaData == null) {
return null;
}
// Is the cached version still current?
if (cached != null) {
boolean isUnchanged = ExternalResourceMetaDataCompare.isDefinitelyUnchanged(
cached.getExternalResourceMetaData(),
new Factory<ExternalResourceMetaData>() {
public ExternalResourceMetaData create() {
return remoteMetaData;
}
}
);
if (isUnchanged) {
LOGGER.info("Cached resource is up-to-date (lastModified: {}). [HTTP: {}]", cached.getExternalLastModified(), location);
// TODO - update the index with the new remote meta-data
return new DefaultLocallyAvailableExternalResource(location, new DefaultLocallyAvailableResource(cached.getCachedFile()), cached.getExternalResourceMetaData());
}
}
// Either no cached, or it's changed. See if we can find something local with the same checksum
boolean hasLocalCandidates = localCandidates != null && !localCandidates.isNone();