About cache cleanup in APP

In general, app has the function of cleaning cache in the settings module. The cache here refers to the disk cache. On the iOS system, the cache is corresponding to the sandbox path.

Generally clear cache is nothing more than two kinds: picture cache and other resource file cache.

The cleanup of picture cache:
, if you use SDWebImage in your project, you can do it directly using the SDWebImage provided good method.

Calculates the size of the picture cache in the disk (without memory processing)

Float folderSize; the //SDWebImage framework itself calculates cache implementations; folderSize = [[SDImageCache, sharedImageCache], getSize]/1024.0/1024.0;

Clear picture cache in disk

- - (void) cleanCache{, [[SDImageCache, sharedImageCache], cleanDisk];}

There are separate file modules in my project, similar to SkyDrive. Support online previews of various files and save them in the sandbox after each preview. For file cleanup in a sandbox, this is the case:

Calculates the cache size of a path in the sandbox

#pragma mark - to clear the cache (NSString *) getCacheCount{float folderSize; if ([self.fileManager fileExistsAtPath: self.cachePath]) {NSArray *childerFiles = [self.fileManager subpathsAtPath:self.cachePath]; for (NSString *fileName in childerFiles *absolutePath [self.cachePath) {NSString = stringByAppendingPathComponent:fileName]; folderSize = [self fileSizeAtPath:absolutePath];}} return [NSString stringWithFormat:@ "%0.1f MB folderSize]";} - (float) (fileSizeAtPath: NSString * path *fileManager=[NSFileManager) {NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:path]) {long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize; return size/1024.0/1024.0;} return 0;}

Clear a cache of a path in the sandbox

- (void) cleanCache: (NSString *) path{NSFileManager *fileManager=[NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:path]) {NSArray *childerFiles=[fileManager subpathsAtPath:path]; for (NSString *fileName in childerFiles) {/ / if necessary, delete the entry conditions to filter out the file NSString *absolutePath=[path stringByAppendingPathComponent:fileName] to [fileManager; removeItemAtPath:absolutePath error:nil];}}}

Finally, add a little bit of cache knowledge: on-demand caching and pre caching.

The main reason why applications need to work offline is to improve the performance shown by the application. You can support offline applications by caching their application content. We can use two different caches to make the application offline. The first is to cache cache request response in this case is the same and the working principle of the Web browser; the second is the pre cache, this is all the contents of the cache (some records or a specific point in time) for offline access.

On demand caching and pre caching, they are very different in design and implementation. According to the needs of the cache refers to the content retrieved from the server in a format stored in the local file system, for each request, the existence of the inspection data cache, only when the data does not exist (or expired) cases obtained from the server. In this case, the cache layer is almost the same as the processor cache. The speed at which data is acquired is more important than the data itself. The pre caching is to place content locally for future access. For pre caching, data loss or cache miss is not acceptable, for example, the user downloads the article to read on the subway, but found that these articles do not exist on the device (about on-demand caching and pre caching details please see the https://my.oschina.net/u/1049180/blog/ 405639)