On iOS where is the NSURLCache cache stored if diskPath:nil?

夙愿已清 提交于 2019-12-08 23:45:02

问题


I've come across code that looks like this:

NSURLCache *URLCache = 
    [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 
                                  diskCapacity:1024 * 1024 * 5 
                                      diskPath:nil];

The problem is that I haven't been able to find what's the expected behavior when diskPath is passed nil. NSURLCache docs don't explicitly describe this situation nor I have been able to figure it out with my own testing.

Where is the cache stored? or is that code above a bug?

Thanks.


回答1:


I had some free time today to do some testing and found the answer. Nothing exciting but if you are curious:

By default iOS will use a database named Cache.db and, as @qegal mentioned, will be stored under the default location.




回答2:


From your linked doc:

In iOS, path is the name of a subdirectory of the application’s default cache directory in which to store the on-disk cache (the subdirectory is created if it does not exist).

My best guess would be that if path is nil (meaning you did not specify a subdirectory), the cache would just be stored in the default cache directory (and not in a subdirectory). I can't test it out right now, because I'm having some computer issues. I'm also guessing that it would be stored in the default cache directory because I'm sure you would get some sort of warning or error either at runtime or when you're writing the code. I know if I wrote something like this:

[array writeToFile: nil atomically:NO];

I would get an error as I did not specify the path to which the file should be written to.

Hope this helps!




回答3:


Under iOS 8.2 the Cache.db file is stored at:

(App Folder)/Library/Caches/com.mycompany.appname/Cache.db

Where com.mycompany.appname is your Bundle ID




回答4:


If diskPath == xxxx, the Cache.db file is store at:

(App Folder)/Library/Caches/com.mycompany.appname/xxxx/Cache.db


来源:https://stackoverflow.com/questions/11300044/on-ios-where-is-the-nsurlcache-cache-stored-if-diskpathnil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!