@@ -116,6 +116,9 @@ - (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory
116
116
// Set decompression to YES
117
117
_shouldDecompressImages = YES ;
118
118
119
+ // memory cache enabled
120
+ _shouldCacheImagesInMemory = YES ;
121
+
119
122
// Disable iCloud
120
123
_shouldDisableiCloud = YES ;
121
124
@@ -196,9 +199,11 @@ - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate image
196
199
if (!image || !key) {
197
200
return ;
198
201
}
199
-
200
- NSUInteger cost = SDCacheCostForImage (image);
201
- [self .memCache setObject: image forKey: key cost: cost];
202
+ // if memory cache is enabled
203
+ if (self.shouldCacheImagesInMemory ) {
204
+ NSUInteger cost = SDCacheCostForImage (image);
205
+ [self .memCache setObject: image forKey: key cost: cost];
206
+ }
202
207
203
208
if (toDisk) {
204
209
dispatch_async (self.ioQueue , ^{
@@ -290,6 +295,7 @@ - (UIImage *)imageFromMemoryCacheForKey:(NSString *)key {
290
295
}
291
296
292
297
- (UIImage *)imageFromDiskCacheForKey : (NSString *)key {
298
+
293
299
// First check the in-memory cache...
294
300
UIImage *image = [self imageFromMemoryCacheForKey: key];
295
301
if (image) {
@@ -298,7 +304,7 @@ - (UIImage *)imageFromDiskCacheForKey:(NSString *)key {
298
304
299
305
// Second check the disk cache...
300
306
UIImage *diskImage = [self diskImageForKey: key];
301
- if (diskImage) {
307
+ if (diskImage && self. shouldCacheImagesInMemory ) {
302
308
NSUInteger cost = SDCacheCostForImage (diskImage);
303
309
[self .memCache setObject: diskImage forKey: key cost: cost];
304
310
}
@@ -369,7 +375,7 @@ - (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompl
369
375
370
376
@autoreleasepool {
371
377
UIImage *diskImage = [self diskImageForKey: key];
372
- if (diskImage) {
378
+ if (diskImage && self. shouldCacheImagesInMemory ) {
373
379
NSUInteger cost = SDCacheCostForImage (diskImage);
374
380
[self .memCache setObject: diskImage forKey: key cost: cost];
375
381
}
@@ -400,9 +406,11 @@ - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion
400
406
if (key == nil ) {
401
407
return ;
402
408
}
403
-
404
- [self .memCache removeObjectForKey: key];
405
-
409
+
410
+ if (self.shouldCacheImagesInMemory ) {
411
+ [self .memCache removeObjectForKey: key];
412
+ }
413
+
406
414
if (fromDisk) {
407
415
dispatch_async (self.ioQueue , ^{
408
416
[_fileManager removeItemAtPath: [self defaultCachePathForKey: key] error: nil ];
0 commit comments