File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -154,4 +154,9 @@ typedef enum SDImageCacheType SDImageCacheType;
154
154
*/
155
155
- (int )getDiskCount ;
156
156
157
+ /* *
158
+ * Asynchronously calculate the disk cache's size.
159
+ */
160
+ - (void )calculateSizeWithCompletionBlock : (void (^)(NSUInteger fileCount, unsigned long long totalSize))completionBlock ;
161
+
157
162
@end
Original file line number Diff line number Diff line change @@ -423,4 +423,37 @@ - (int)getDiskCount
423
423
return count;
424
424
}
425
425
426
+ - (void )calculateSizeWithCompletionBlock : (void (^)(NSUInteger fileCount, unsigned long long totalSize))completionBlock
427
+ {
428
+ NSURL *diskCacheURL = [NSURL fileURLWithPath: self .diskCachePath isDirectory: YES ];
429
+
430
+ dispatch_async (self.ioQueue , ^
431
+ {
432
+ NSUInteger fileCount = 0 ;
433
+ unsigned long long totalSize = 0 ;
434
+
435
+ NSFileManager *fileManager = [NSFileManager defaultManager ];
436
+ NSDirectoryEnumerator *fileEnumerator = [fileManager enumeratorAtURL: diskCacheURL
437
+ includingPropertiesForKeys: @[ NSFileSize ]
438
+ options: NSDirectoryEnumerationSkipsHiddenFiles
439
+ errorHandler: NULL ];
440
+
441
+ for (NSURL *fileURL in fileEnumerator)
442
+ {
443
+ NSNumber *fileSize;
444
+ [fileURL getResourceValue: &fileSize forKey: NSURLFileSizeKey error: NULL ];
445
+ totalSize += [fileSize unsignedLongLongValue ];
446
+ fileCount += 1 ;
447
+ }
448
+
449
+ if (completionBlock)
450
+ {
451
+ dispatch_async (dispatch_get_main_queue (), ^
452
+ {
453
+ completionBlock (fileCount, totalSize);
454
+ });
455
+ }
456
+ });
457
+ }
458
+
426
459
@end
You can’t perform that action at this time.
0 commit comments