rs/SDWebImage — Issue #49: Store to disk
Author: dqueffeulouatw
Created: 2011-11-24 09:11:21+00:00
State: open

Hi,

I'm trying to store UIIMage to disk but it doesn't work. I look at the code and found :

- (void)storeImage:(UIImage *)image imageData:(NSData *)data forKey:(NSString *)key toDisk:(BOOL)toDisk
{
if (!image || !key)
{
return;
}

[memCache setObject:image forKey:key];

if (toDisk)
{
if (!data) return;
NSArray *keyWithData;
if (data)
{
keyWithData = [NSArray arrayWithObjects:key, data, nil];
}
else
{
keyWithData = [NSArray arrayWithObjects:key, nil];
}
[cacheInQueue addOperation:[[[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(storeKeyWithDataToDisk:)
object:keyWithData] autorelease]];
}
}

I cannot understand the following test on data:

if (!data) return;
NSArray *keyWithData;
if (data)
{
keyWithData = [NSArray arrayWithObjects:key, data, nil];
}
else

It has no meaning to me.

BTW the call to
[[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];

and then to
[self storeImage:image imageData:nil forKey:key toDisk:YES];

result to ... nothing stored to disk because data is nil.

So at least your documentation is wrong and I must provide myself the imageData to the method:
storeImage: imageData: forKey: toDisk:

in order the image to be stored on disk.