Sdwebimage How to get the cache size and clear the cache
1. Locate the Sdimagecache Class 2. Add the following method:
-(float) checktmpsize {
float totalsize = 0;
Nsdirectoryenumerator *fileenumerator = [[Nsfilemanager Defaultmanager] enumeratoratpath:diskcachepath];
For (NSString *filename in FileEnumerator) {
NSString *filepath = [Diskcachepath stringbyappendingpathcomponent:filename];
Nsdictionary *attrs = [[Nsfilemanager Defaultmanager] Attributesofitematpath:filepath Error:nil];
unsigned long long length = [Attrs fileSize];
TotalSize + = length/1024.0/1024.0;
}//NSLog (@ "tmp size is%.2f", totalsize); return totalsize;
}
3. Use #pragma to clean up cached images in Settings (void) cleartmppics {[[Sdimagecache Sharedimagecache] cleardisk]; [[Sdimagecache Sharedimagecache] clearmemory];//optional DLog (@ "clear disk"); float tmpsize = [[Sdimagecache Sharedimagecache] checktmpsize]; NSString *clearcachename = tmpsize >= 1? [NSString stringwithformat:@ "cleanup cache (%.2FM)", tmpsize]: [NSString stringwithformat:@ "clean cache (%.2FK)", tmpsize * 1024]; [Configdataarray Replaceobjectatindex:2 Withobject:clearcachename]; [Configtableview Reloaddata]; }
Sdwebimage How to get the cache size and clear the cache