is network cache stays after iOS application is removed and reinstall - ios

I have an iOS application that fetches network resources by using URLRequest with default cachePolicy. I would like to know if:
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)
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.

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.

Related

How often does iOS Safari clear its cache?

I use mobile Safari cache to store some data that I want to be persistent, so I would prefer that they would survive both Safari restarts and iOS restarts.
(Please don't suggest me to use cookies or Local Storage here - that's not what I am asking about.)
However I have read some new and some old reports that Safari clears its cache on Safari restart. But my non-scientific tests on Safari 8.3 showed me that sometimes this cache can in fact not only survive application restart but even the iOS reboot (!).
So I am a bit confused at this point.
Are the rules of iOS Safari cache clearing documented somewhere?
Does any of you know them and can explain them to me (and the world ;)?
Hope someone find that I'm wrong but..
I searched a lot and I guess there are no resources about how the automatic cleaning policy works in Safari. And knowing Apple policy I guess that it's simply because this information is not necessary both for users and developers.
If you want to ask to Safari to protect your cache, you can use the Manifest File as described there:
https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/Client-SideStorage/Client-SideStorage.html#//apple_ref/doc/uid/TP40002051-CH4-SW1
I'm not sure about ios safari, but in general the browser reserves some storage space for cached items. When that space fills up, it starts deleting the cache.
Another factor that may trigger the cache deletion may be when the operating system tries to clear the temporary files.
So, a short answer would be: you don't know. That depends from user to user of how often it is deleted.

iOS - Can saving to Library/Caches/ result in error?

If an app starts saving virtually unlimited images (on demand) to the /Library/Caches directory for caching purpose, what will happen when the storage is full? Will saving to the caches folder result in error? OR If the app is open, can the cache of the open app be purged by iOS automatically? If not, is it the responsibility of the developer to initiate this purging process for the open app? OR Is it guaranteed that an attempt to save an image to /Library/Caches will always be successful regardless of whether the purging takes place or not? (Cached images are cleaned by the app on exit).
Yes, it may result in error. No, it will not be purged by iOS automatically while an app is running. Quote from the docs:
Caches
On iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running
So it's your responsibility to cleanup the caches directory while running. However you would probably meet this error in a very rare cases since iOS will try to remove caches of other apps that are not running.

Blackberry app version update deletes persistent store object on some devices

I have a Blackberry app that stores an object in the persistent store. After updating the app, it is supposed to read the existing value from the persistent store, if any, and continue to use that value. This works on some devices, but does not work on others. I tested on several devices running OS version 7, all of which work as expected. However on a device using version 5 and another using version 6, the object is no longer readable in the persistent store.
This is the case even if I don't change anything about the app other than the version number. Same exact class/object being saved & loaded from the persistent store, and same object ID used to access it.
The process I'm following to reproduce this is:
Completely delete the app & all it's data using the command line.
Load a version of the app, by downloading a .jad file from a browser, verify that it stores data in the persistent store.
While the app is running in the background, load a later version via browser download of the .jad file.
After downloading the later version, the system asks if I want to replace the previous version, and I confirm that I do.
The system loads the new version, and prompts that I must reboot for the change to take effect. I select "Reboot".
Device reboots. The later version is running but cannot read the object from the persistent store.
A device on which I can consistently reproduce this issue is a Blackberry 9800 (Torch) running 6.0 Bundle 2647.
As mentioned above this only happens on some, not all, devices, which makes me think something other than a coding bug may be going on here.
Anyone have ideas about this issue or how to debug it further?
Peculiar case.
Are you sure the persistent storage is being committed? Something similar generally occurs for me when data has been stored in the storage but not committed. If that is the case, and you load the older version, store some data and reboot your device, the data will not be stored in persistence.
You mentioned that the app is still running in the background when you load a later version. You may want to check whether commit() gets executed or not.

iOS 5 network data being persistant even after refresh/restart of app

I have an app that grabs (async) a JSON file on the network during startup. The app starts fresh when restarted. It has some config settings, as the app acts as a shell. My issue is when I change the config file on the server, the old settings remain the same. As if it's being cached. This has happened in several apps I have, and it started when I updated to iOS5.
I have an Android app that's equivalent, but does not suffer from this issue.
NSURLRequestCachePolicy is correct.

iOS 5 Library/Caches purge callback

Is it possible for the Caches directory to be purged while my app is running, and if so, will my app be notified in any way that this has occured?
Thanks!
I don't know if it is possible for the cleaning to occur while it is running (though my impression is no). However if you want to detect when the cleaning has occurred you can set a test file into the caches directory and check for it's presence.
File Gone = Cache Purged
No, according to the docs:
On iOS 5.0 and later, the system may delete the Caches directory on rare occasions when the system is very low on disk space. This will never occur while an app is running. However, you should be aware that iTunes restore is not necessarily the only condition under which the Caches directory can be erased.

Resources