iOS 徹底清空APP快取

2021-08-08 16:35:36 字數 1377 閱讀 1905

可以好不誇張的說,網上很多清空快取的例子都存在這樣活著那樣的錯誤,要麼不準確,要麼清理不徹底。

另外,很多地方計算快取時轉換單位的那一步,都是按1024計算,經過本人數十次驗證,應該按1000計算。

本人的這個demo也有參考網友的demo,但是進行了大修復。

以下是乙個封裝的工具類: 

.h檔案

#import

@inte***ce

clearcachetool : nsobject/**

* 獲取快取大小 */

+ (nsstring *)getcachesize;/**

* 清理快取 */

+(bool)clearcaches;

@end

.m檔案

#import "clearcachetool.h"

#define filemanager [nsfilemanager defaultmanager]

#define cachepath [nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes) lastobject]

@implementation clearcachetool

// 獲取cachepath路徑下資料夾大小

+ (nsstring *)getcachesize

//發布

#else

#endif

//獲取「cachepath」資料夾下面的所有檔案

nsarray *subpatharray= [filemanager subpathsatpath:cachepath];

nsstring *filepath = nil;

long long totalsize = 0;

for (nsstring *subpath in subpatharray)

// 將資料夾大小轉換為 m/kb/b

nsstring *totalsizestring = nil;

if (totalsize > 1000 * 1000) else if (totalsize > 1000) else

return totalsizestring;

}// 清除cachepath資料夾下快取大小

+ (bool)clearcaches

nserror *error = nil;

nsstring *filepath = nil;

bool flag = no;

for (nsstring *subpath in subpatharray) }}

if (no == flag)

return flag;

}@end

jsp清空快取

快取 快取就是資料交換的緩衝區 稱作cache 快取的思想可以應用在軟體分層的各個層面。它是一種內部機制,對外界而言,是不可感知的。資料庫本身有快取,持久層也可以快取。比如 hibernate,還分1級和2級快取 業務層也可以有快取 但一般來說,這是乙個過程域,不會設快取 server上的快取機制 ...

Android 清空快取

public class param context param catchpathstring 快取路徑 return throws exception 當前快取大小 public static string gettotalcachesize context context,string cat...

清空掉taxonomy get tree快取

taxonomy get tree vid,parent,depth,max depth 這個函式生成乙個詞彙表的層級化表示。引數 vid就是用來生成層級樹的詞彙表的詞彙表id。如果你不想為乙個詞彙表生成乙個整樹的話,而只想生成乙個以 parent宣告的詞語id為根的子樹,這時你可以宣告引數 par...