Cache image data, as NSPurgeableData, rather than UIImage/NSImage
This commit is contained in:
parent
a37cda1032
commit
d5a972e549
3 changed files with 13 additions and 37 deletions
|
|
@ -57,21 +57,14 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Stores an image into cache, associated with a given URL and cache name.
|
Stores image data into cache, associated with a given URL and cache name.
|
||||||
|
|
||||||
@param image The image to be stored in cache.
|
@param imageData The image data to be stored in cache.
|
||||||
@param url The URL to be associated with the image.
|
@param url The URL to be associated with the image.
|
||||||
@param cacheName The cache name to be associated with the image in the cache. This allows for multiple versions of an image to be associated for a single URL, such as image thumbnails, for instance.
|
@param cacheName The cache name to be associated with the image in the cache. This allows for multiple versions of an image to be associated for a single URL, such as image thumbnails, for instance.
|
||||||
*/
|
*/
|
||||||
|
- (void)cacheImageData:(NSData *)imageData
|
||||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
|
||||||
- (void)cacheImage:(UIImage *)image
|
|
||||||
forURL:(NSURL *)url
|
forURL:(NSURL *)url
|
||||||
cacheName:(NSString *)cacheName;
|
cacheName:(NSString *)cacheName;
|
||||||
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
|
||||||
- (void)cacheImage:(NSImage *)image
|
|
||||||
forURL:(NSURL *)url
|
|
||||||
cacheName:(NSString *)cacheName;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -43,38 +43,21 @@ static inline NSString * AFImageCacheKeyFromURLAndCacheName(NSURL *url, NSString
|
||||||
- (UIImage *)cachedImageForURL:(NSURL *)url
|
- (UIImage *)cachedImageForURL:(NSURL *)url
|
||||||
cacheName:(NSString *)cacheName
|
cacheName:(NSString *)cacheName
|
||||||
{
|
{
|
||||||
return [self objectForKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)];
|
return [UIImage imageWithData:[self objectForKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)]];
|
||||||
}
|
}
|
||||||
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
||||||
- (NSImage *)cachedImageForURL:(NSURL *)url
|
- (NSImage *)cachedImageForURL:(NSURL *)url
|
||||||
cacheName:(NSString *)cacheName
|
cacheName:(NSString *)cacheName
|
||||||
{
|
{
|
||||||
return [self objectForKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)];
|
return [[[NSImage alloc] initWithData:[self objectForKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)]] autorelease];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
- (void)cacheImageData:(NSData *)imageData
|
||||||
- (void)cacheImage:(UIImage *)image
|
|
||||||
forURL:(NSURL *)url
|
forURL:(NSURL *)url
|
||||||
cacheName:(NSString *)cacheName
|
cacheName:(NSString *)cacheName
|
||||||
{
|
{
|
||||||
if (!image) {
|
[self setObject:[NSPurgeableData dataWithData:imageData] forKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)];
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[self setObject:image forKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)];
|
|
||||||
}
|
|
||||||
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
|
||||||
- (void)cacheImage:(NSImage *)image
|
|
||||||
forURL:(NSURL *)url
|
|
||||||
cacheName:(NSString *)cacheName
|
|
||||||
{
|
|
||||||
if (!image) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
[self setObject:image forKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)];
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ static dispatch_queue_t image_request_operation_processing_queue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([operation.request cachePolicy] != NSURLCacheStorageNotAllowed) {
|
if ([operation.request cachePolicy] != NSURLCacheStorageNotAllowed) {
|
||||||
[[AFImageCache sharedImageCache] cacheImage:image forURL:[operation.request URL] cacheName:cacheNameOrNil];
|
[[AFImageCache sharedImageCache] cacheImageData:operation.responseData forURL:[operation.request URL] cacheName:cacheNameOrNil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -147,7 +147,7 @@ static dispatch_queue_t image_request_operation_processing_queue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([operation.request cachePolicy] != NSURLCacheStorageNotAllowed) {
|
if ([operation.request cachePolicy] != NSURLCacheStorageNotAllowed) {
|
||||||
[[AFImageCache sharedImageCache] cacheImage:image forURL:[operation.request URL] cacheName:cacheNameOrNil];
|
[[AFImageCache sharedImageCache] cacheImageData:operation.responseData forURL:[operation.request URL] cacheName:cacheNameOrNil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue