Remove the need for storeDataQueue dictionnary which required synchronization
This commit is contained in:
parent
9f492ccdf8
commit
1fe20c25d6
|
@ -11,7 +11,7 @@
|
|||
|
||||
@interface SDImageCache : NSObject
|
||||
{
|
||||
NSMutableDictionary *memCache, *storeDataQueue;
|
||||
NSMutableDictionary *memCache;
|
||||
NSString *diskCachePath;
|
||||
NSOperationQueue *cacheInQueue, *cacheOutQueue;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ static SDImageCache *instance;
|
|||
memCache = [[NSMutableDictionary alloc] init];
|
||||
|
||||
// Init the disk cache
|
||||
storeDataQueue = [[NSMutableDictionary alloc] init];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
diskCachePath = [[[paths objectAtIndex:0] stringByAppendingPathComponent:@"ImageCache"] retain];
|
||||
|
||||
|
@ -75,7 +74,6 @@ static SDImageCache *instance;
|
|||
[memCache release], memCache = nil;
|
||||
[diskCachePath release], diskCachePath = nil;
|
||||
[cacheInQueue release], cacheInQueue = nil;
|
||||
[storeDataQueue release], storeDataQueue = nil;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
|
@ -107,19 +105,17 @@ static SDImageCache *instance;
|
|||
return [diskCachePath stringByAppendingPathComponent:filename];
|
||||
}
|
||||
|
||||
- (void)storeKeyToDisk:(NSString *)key
|
||||
- (void)storeKeyWithDataToDisk:(NSArray *)keyAndData
|
||||
{
|
||||
// Can't use defaultManager another thread
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
|
||||
NSData *data = [storeDataQueue objectForKey:key];
|
||||
NSString *key = [keyAndData objectAtIndex:0];
|
||||
NSData *data = [keyAndData count] > 1 ? [keyAndData objectAtIndex:1] : nil;
|
||||
|
||||
if (data)
|
||||
{
|
||||
[fileManager createFileAtPath:[self cachePathForKey:key] contents:data attributes:nil];
|
||||
@synchronized(storeDataQueue)
|
||||
{
|
||||
[storeDataQueue removeObjectForKey:key];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -193,8 +189,18 @@ static SDImageCache *instance;
|
|||
|
||||
if (toDisk)
|
||||
{
|
||||
[storeDataQueue setObject:data forKey:key];
|
||||
[cacheInQueue addOperation:[[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(storeKeyToDisk:) object:key] autorelease]];
|
||||
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]];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue