Add imageFromMemoryCacheForKey: method to synchronously query the memory cache (fix #263)
This commit is contained in:
parent
555a320b9e
commit
1e53e91513
|
@ -145,8 +145,7 @@ SDImageCache *imageCache = [SDImageCache.alloc initWithNamespace:@"myNamespace"]
|
|||
```
|
||||
|
||||
By default SDImageCache will lookup the disk cache if an image can't be found in the memory cache.
|
||||
You can prevent this from happening by calling the alternative method imageFromKey:fromDisk: with a
|
||||
negative second argument.
|
||||
You can prevent this from happening by calling the alternative method `imageFromMemoryCacheForKey:`.
|
||||
|
||||
To store an image into the cache, you use the storeImage:forKey: method:
|
||||
|
||||
|
|
|
@ -87,6 +87,13 @@ typedef enum SDImageCacheType SDImageCacheType;
|
|||
*/
|
||||
- (void)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *image, SDImageCacheType cacheType))doneBlock;
|
||||
|
||||
/**
|
||||
* Query the memory cache.
|
||||
*
|
||||
* @param key The unique key used to store the wanted image
|
||||
*/
|
||||
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key;
|
||||
|
||||
/**
|
||||
* Remove the image from memory and disk cache synchronousely
|
||||
*
|
||||
|
|
|
@ -150,6 +150,11 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
[self storeImage:image imageData:nil forKey:key toDisk:toDisk];
|
||||
}
|
||||
|
||||
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key
|
||||
{
|
||||
return [self.memCache objectForKey:key];
|
||||
}
|
||||
|
||||
- (void)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *image, SDImageCacheType cacheType))doneBlock
|
||||
{
|
||||
if (!doneBlock) return;
|
||||
|
@ -161,7 +166,7 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
}
|
||||
|
||||
// First check the in-memory cache...
|
||||
UIImage *image = [self.memCache objectForKey:key];
|
||||
UIImage *image = [self imageFromMemoryCacheForKey:key];
|
||||
if (image)
|
||||
{
|
||||
doneBlock(image, SDImageCacheTypeMemory);
|
||||
|
|
Loading…
Reference in New Issue