@@ -25,7 +25,6 @@ - (id)init
25
25
memCache = [[NSMutableDictionary alloc ] init ];
26
26
27
27
// Init the disk cache
28
- storeDataQueue = [[NSMutableDictionary alloc ] init ];
29
28
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES );
30
29
diskCachePath = [[[paths objectAtIndex: 0 ] stringByAppendingPathComponent: @" ImageCache" ] retain ];
31
30
@@ -75,7 +74,6 @@ - (void)dealloc
75
74
[memCache release ], memCache = nil ;
76
75
[diskCachePath release ], diskCachePath = nil ;
77
76
[cacheInQueue release ], cacheInQueue = nil ;
78
- [storeDataQueue release ], storeDataQueue = nil ;
79
77
80
78
[[NSNotificationCenter defaultCenter ] removeObserver: self ];
81
79
@@ -107,19 +105,17 @@ - (NSString *)cachePathForKey:(NSString *)key
107
105
return [diskCachePath stringByAppendingPathComponent: filename];
108
106
}
109
107
110
- - (void )storeKeyToDisk : ( NSString *)key
108
+ - (void )storeKeyWithDataToDisk : ( NSArray *)keyAndData
111
109
{
112
110
// Can't use defaultManager another thread
113
111
NSFileManager *fileManager = [[NSFileManager alloc ] init ];
114
112
115
- NSData *data = [storeDataQueue objectForKey: key];
113
+ NSString *key = [keyAndData objectAtIndex: 0 ];
114
+ NSData *data = [keyAndData count ] > 1 ? [keyAndData objectAtIndex: 1 ] : nil ;
115
+
116
116
if (data)
117
117
{
118
118
[fileManager createFileAtPath: [self cachePathForKey: key] contents: data attributes: nil ];
119
- @synchronized (storeDataQueue)
120
- {
121
- [storeDataQueue removeObjectForKey: key];
122
- }
123
119
}
124
120
else
125
121
{
@@ -193,8 +189,18 @@ - (void)storeImage:(UIImage *)image imageData:(NSData *)data forKey:(NSString *)
193
189
194
190
if (toDisk)
195
191
{
196
- [storeDataQueue setObject: data forKey: key];
197
- [cacheInQueue addOperation: [[[NSInvocationOperation alloc ] initWithTarget: self selector: @selector (storeKeyToDisk: ) object: key] autorelease ]];
192
+ NSArray *keyWithData;
193
+ if (data)
194
+ {
195
+ keyWithData = [NSArray arrayWithObjects: key, data, nil ];
196
+ }
197
+ else
198
+ {
199
+ keyWithData = [NSArray arrayWithObjects: key, nil ];
200
+ }
201
+ [cacheInQueue addOperation: [[[NSInvocationOperation alloc ] initWithTarget: self
202
+ selector: @selector (storeKeyWithDataToDisk: )
203
+ object: keyWithData] autorelease ]];
198
204
}
199
205
}
200
206
0 commit comments