在SDImageCache文件補(bǔ)充一個(gè)方法,刪除給到的URL組意外的緩存.
在一個(gè)項(xiàng)目中,有很多緩存圖片,有些特定的圖片不想清楚,然而我們不可能找到像刪除的圖片進(jìn)行刪除.所以反過來寫了這個(gè)方法
-(void)removeImageCacheInAdditionToTheFavoritesWithURLs:(NSArray*)URLs{
if(URLs.count==0) {
[selfclearDisk];
return;
}
NSArray*files = [[NSFileManagerdefaultManager]subpathsOfDirectoryAtPath:self.diskCachePatherror:nil];
NSMutableArray*mutFiles = [NSMutableArrayarray];
NSMutableArray*deleteFiles = [NSMutableArrayarray];
for(NSString*fileStrinfiles) {
[mutFilesaddObject:[NSStringstringWithFormat:@"%@/%@",self.diskCachePath,fileStr]];
[deleteFilesaddObject:[NSStringstringWithFormat:@"%@/%@",self.diskCachePath,fileStr]];
}
for(NSString*urlStrinURLs) {
NSString*fileName = [selfdefaultCachePathForKey:urlStr];
if([mutFilescontainsObject:fileName]) {
[deleteFilesremoveObject:fileName];
}
}
for(NSString*deleteFileNameindeleteFiles) {
[_fileManagerremoveItemAtPath:deleteFileNameerror:nil];
}
}