//获取沙盒路径 计算缓存大小
self.filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSFileManager *fileManager = [NSFileManager defaultManager];
float size =0;
NSArray* array = [fileManager contentsOfDirectoryAtPath:self.filePath error:nil];
for(int i = 0; i<[array count]; i++)
{
NSString *fullPath = [self.filePath stringByAppendingPathComponent:[array objectAtIndex:i]];
NSDictionary *fileAttributeDic=[fileManager attributesOfItemAtPath:fullPath error:nil];
size+= fileAttributeDic.fileSize/ 1024.0/1024.0;
}
// NSLog(@" size = %.2f",size);
//删除沙盒 document
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray* array = [fileManager contentsOfDirectoryAtPath:self.filePath error:nil];
for(int i = 0; i<[array count]; i++)
{
NSString *fullPath = [self.filePath stringByAppendingPathComponent:[array objectAtIndex:i]];
[fileManager removeItemAtPath:fullPath error:nil];
}
//清除SD缓存
[[SDImageCache sharedImageCache] clearDisk];
//计算SD缓存
NSInteger sizeSD = [[SDImageCache sharedImageCache] getSize];
float totalSize=sizeSD/1024.0/1024.0;//转换成M
// NSLog(@"size===%.2f",totalSize);
self.cacheLabel.text = [NSString stringWithFormat:@"%.2f MB",size+totalSize];