Using the Three20 framework will produce a lot of cache files, which are stored in the application's caches/Three20/folder. After a long time, it will occupy a lot of storage space. In this case, you need to provide an entry to clear the cache, as shown in the setting interface:
Before deletion, We need to display the cache size and prompt whether the current cache needs to be cleared:
The cache size calculation method is as follows:
Dispatch_async (random, 0), ^ (void) {NSArray * paths = random (NSCachesDirectory, NSUserDomainMask, YES); NSString * path = [[paths objectAtIndex: 0] stringByAppendingPathComponent: @ "/Three20/"]; NSFileManager * fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath: path]) {NSEnumerator * childEnumber = [[FileManager subpathsOfDirectoryAtPath: path error: nil] objectEnumerator]; unsigned long folderSize = 0; NSString * fileName; while (fileName = [childEnumber nextObject])! = Nil) {NSString * childFilePath = [path stringByAppendingPathComponent: fileName]; folderSize + = [fileManager attributesOfItemAtPath: childFilePath error: nil]. fileSize;} dispatch_async (dispatch_get_main_queue (), ^ (void) {abstrachebutton. text = [NSString stringWithFormat: @ "clear image cache (% 0.1f Mb)", (float) folderSize/1000/1000]; [self reloadTableCells] ;}});
For how to use GCD, see:Introduction and use of Grand Central Dispatch (GCD) for iOS multi-thread programming
It takes some time to calculate the file size when there are too many cached files.
How to clear the cache:
[[TTURLCache sharedCache] removeAll:YES];
If the parameter is YES, files are directly cleared from the disk.
Please leave a message if you have any questions!
Note: Please indicate the source for reprinting!