1

I have an iOS application that fetches network resources by using URLRequest with default cachePolicy. I would like to know if:

  1. When the application is deleted from my device, is all cached responses are removed as well? Or do they stay somewhere in the device? (until they are expired)
  2. If yes, if I install the app again in that device, when I launch the app, it will get the cached response stored in iOS device instead of fetching original resources from back-end (if the responses are still valid, of course)?

Below is the behaviour of default Cache Policy explained by Apple:

Thanks.

enter image description here

Duyen-Hoa
  • 14,296
  • 4
  • 30
  • 40

1 Answers1

2

The caches are stored in a file in your app’s container directory (specifically, Caches/BUNDLE_ID/Cache.db in iOS, or Library/Caches/BUNDLE_ID/Cache.db in macOS, IIRC). When the app goes away, so does the cache, and as far as I’m aware, they are never stored in iCloud backups or anything, so there should be no possibility of them resurfacing.

But be aware that other things can cache responses (e.g. proxy servers on the local network), so if your goal is to completely eliminate any possibility of getting a stale response, you should explicitly disable caching for the request.

If your goal is to have a prewarmed cache, you could distribute a cache file in your app bundle and make a copy of it on first launch before enabling the disk cache, but you are probably better off downloading a ZIP archive and managing files on disk yourself if you are trying to do any sort of offline mode, rather than trying to bend NSURLCache to your will.

dgatwood
  • 9,519
  • 1
  • 24
  • 48
  • My goal is to know where the network response is cached. I cannot find any Apple document about that. I got a issue when iOS app still get old datas even back-end caches have been wiped out. I was using proxy but I disabled the cache during my test. – Duyen-Hoa Jun 25 '18 at 14:52
  • By default, it is in APP_CONTAINER/Caches/BUNDLE_ID/Cache.db. – dgatwood Jun 25 '18 at 21:35
  • That's true. Thank you, I found it! – Duyen-Hoa Jun 26 '18 at 14:11