/**緩存
* 清理緩存文件async
*spa
* @param path 地址.net
*orm
* @returnrem
*/get
+(void)clearCache:(NSString *)path{string
NSFileManager *fileManager=[NSFileManager defaultManager];it
if ([fileManager fileExistsAtPath:path]) {ast
NSArray *childerFiles=[fileManager subpathsAtPath:path];
for (NSString *fileName in childerFiles) {
//若有須要,加入條件,過濾掉不想刪除的文件
NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
[fileManager removeItemAtPath:absolutePath error:nil];
}
}
[[SDImageCache sharedImageCache] cleanDisk];
}
//緩存大小
+ (NSString *)CachesSize{
// 清除緩存
CGFloat size = [self folderSizeAtPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject];
NSString *message = size > 1 ? [NSString stringWithFormat:@"%.f M", size] : [NSString stringWithFormat:@"%.f K", size * 1024.0];
return message;
}
//清除緩存
+ (void)cleanCaches{
[self clearCache:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject];
[self clearCache:NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).firstObject];
[self clearCache:NSTemporaryDirectory()];
}
//清理緩存
-(void) clearCaches
{
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
for (NSString *p in files) {
NSError *error;
NSString *path = [cachPath stringByAppendingPathComponent:p];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
}
}
});
}