Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Add Image query cache result type #23608

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function prefetch(url: string) {

async function queryCache(
urls: Array<string>,
): Promise<Map<string, 'memory' | 'disk'>> {
): Promise<Map<string, 'memory' | 'disk' | 'disk/memory'>> {
return await ImageViewManager.queryCache(urls);
}

Expand Down
8 changes: 6 additions & 2 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,13 @@ - (NSDictionary *)getImageCacheStatus:(NSArray *)requests
NSCachedURLResponse *cachedResponse = [NSURLCache.sharedURLCache cachedResponseForRequest:urlRequest];
if (cachedResponse) {
if (cachedResponse.storagePolicy == NSURLCacheStorageAllowedInMemoryOnly) {
[results setObject:@"memory" forKey:urlRequest.URL.absoluteString];
results[urlRequest.URL.absoluteString] = @"memory";
} else if (NSURLCache.sharedURLCache.currentMemoryUsage == 0) {
// We can't check whether the file is cached on disk or memory.
// However, if currentMemoryUsage is disabled, it must be read from disk.
results[urlRequest.URL.absoluteString] = @"disk";
} else {
[results setObject:@"disk" forKey:urlRequest.URL.absoluteString];
results[urlRequest.URL.absoluteString] = @"disk/memory";
}
}
}
Expand Down