Three20 learning to clear the network Cache

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.