/** 緩存大小 */
@property (nonatomic, assign) NSInteger fileTotlaSize;
/開始計算緩存大小
- (void)calculateCacheSizeWithoutURLCache:(BOOL)withoutURLCache{
//開始計算緩存大小
_fileTotlaSize = 0;
WS(weakSelf);
if(withoutURLCache ==NO) {
//計算APP中H5占用內(nèi)存和硬盤空間小
_fileTotlaSize += [NSURLCache sharedURLCache].currentMemoryUsage;
_fileTotlaSize += [NSURLCache sharedURLCache].currentDiskUsage;
}
//計算APP下載的圖片大小
[SDWebImageManager.sharedManager.imageCache calculateSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
weakSelf.fileTotlaSize+= totalSize;
[weakSelf updateCacheSize];
}];
}
- (void)updateCacheSize{
[_cacheLabel setText:[NSString stringWithFormat:@"%.2fM",_fileTotlaSize/1024.0f/1024.0f]];
[MessageTool hideCurrentProgressHUD];
}
1.//刪除本地H5緩存數(shù)據(jù)
+ (void)cleanCacheAndCookie{
if(@available(iOS9.0, *)) {
//清除WKWebView的緩存
NSSet*websiteDataTypes = [WKWebsiteDataStoreallWebsiteDataTypes];
// Date from
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
// Execute
dispatch_async(dispatch_get_main_queue(), ^{
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
}];
});
}
NSURLCache * cache = [NSURLCache sharedURLCache];
[cacheremoveAllCachedResponses];
[cachesetDiskCapacity:0];
[cachesetMemoryCapacity:0];
}
2./ /刪除SDWebImage 下載圖片緩存數(shù)據(jù)
[SDWebImageManager.sharedManager.imageCache clearMemory];
//刪除下載圖片本地數(shù)據(jù)
[SDWebImageManager.sharedManager.imageCache clearDiskOnCompletion:^{
}];
3.//刪除本地簡單存儲數(shù)據(jù)
#define SimpleSavePath [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"SFNetwork"]
+ (void)clearSimpleSaveLocallyData{
//刪除簡單存儲文件夾
NSFileManager *fm = [NSFileManager defaultManager];
if ([fm removeItemAtPath:SimpleSavePath error:nil]) {
NSLog(@"刪除簡單本地存儲文件夾成功!");
}
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。