如何在iOS应用中限制WebView的缓存大小?
我可以使用其中一种代码吗?
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:X];
[[NSURLCache sharedURLCache] setMemoryCapacity:X];
或者是否可以通过单击按钮来清除缓存?
答案 0 :(得分:0)
您可以使用以下内容设置缓存大小:
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:MEMORY_CAPACITY
diskCapacity:DISK_CAPACITY
diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];
其中MEMORY_CAPACITY和DISK_CAPACITY是NSUInteger值,以字节为单位。