SDWebImage清理图片缓存方法

//获取当前缓存大小
@property (nonatomic, assign) NSUInteger tmpSize;

//获取缓存大小并储存
_tmpSize=[[SDImageCache sharedImageCache]getSize];
        NSString* tempSize=[NSString stringWithFormat:@"%.2fM", self.tmpSize /1024.f /1024.f];
        [[NSUserDefaults standardUserDefaults]setObject:tempSize forKey:@"tempSize”];

        [[SDImageCache sharedImageCache]clearDisk];
        [[SDImageCache sharedImageCache]clearMemory];
        __weak typeof(self) myself = self;
        [[SDImageCache sharedImageCache]calculateSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
            NSLog(@"%lu", (unsigned long)totalSize);
            [myself refreshCache];
        }];

/**
 *  缓存清理完毕后刷新数据
 */
-(void)refreshCache
{
    NSString* tempSize=[[NSUserDefaults standardUserDefaults]objectForKey:@"tempSize"];
    NSString *str = [NSString stringWithFormat:@"缓存清理成功,共清理了%@缓存",tempSize];
    ALERT_HOME(@"清理成功", str);
    [_shezhiTableView reloadData];
}

 

posted @ 2016-05-23 16:42  death3721  阅读(794)  评论(0编辑  收藏  举报