2

I have a simple iOS app that loads and list of links and presents them in a UIWebview. The app, when installed, is ~2MB. After clicking around through some of the links, I noticed that the disk usage of documents and data jumped to over 10MB. As a couple days went on, I noticed the disk usage continued to grow. My question is, what is the best way to manage disk storage on iOS?

The goal of this app is to be very minimal and not heavy on resources, but I'm concerned that it will continue to consume more and more disk space with, what I assume is, cached web content. Should I / is there a way to set a cache size? Or does iOS just handle this for me and delete old data eventually?

4

2 回答 2

2

指定缓存大小:

int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
[NSURLCache setSharedURLCache:sharedCache];

删除所有存储的缓存 URL 响应:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

希望对你有用!

于 2013-05-17T02:10:27.347 回答
2

不要过早优化!磁盘上的资源不会对 RAM 内存造成压力,所以不用担心。如果系统正在为您管理缓存,您无法猜测它会做什么。如果它需要清理空间,它大概会清理空间。别担心,开心就好。

现在,话虽如此,您确实可以控制 NSURLRequest 缓存策略。查看 NSURLRequest 文档以了解更多信息。

于 2013-05-17T01:33:38.817 回答