How often does iOS Safari clear its cache? - ios

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.

Related

iOS Safari/WebKit current state of PWA persistence as of version 15.2

I am reevaluating PWA feasibility for mostly offline based, occasionally used applications.
So far I had experience that PWAs on iOS does not have permanent storage as the website allocated space is often subject to cleanup either due to lack of space on a device or after N (I guess 7) days of application/website inactivity. I am aiming for fully installed PWA's (homepage).
According to mozilla docs Safari should from version 15.2 fully implement the StorageManager persist API.
On the other hand I have not found such a statement in Safari release notes.
Can someone confirm or disconfirm the persistence of PWA's on iOS?
Without full persistence occasionally used offline ready PWA applications on iOS are no go zone. The only remaining alternative remains cordova or capacitor then. Or other more exotic solutions then (like React Native).
Thanks.
I have not seen a definitive source, but this rather wordy article about PWA's on IOS says:
"There is a 50MB service worker cache limit, but that does not mean you cannot persist more data. IndexedDB allows you to store a few GBs of data. It really depends, like other platforms, on the available space.
There is no native add to homescreen prompt, but other than Chrome and Edge no one else does either.Unused web apps that have not been added to the homescreen will have their cached assets purged after 7 days. This is less of a problem than most think."
The key is "added to the home screen" for iOS Safari - per this.
But I don't see a definitive answer from Apple.
/https://love2dev.com/pwa/ios/

is network cache stays after iOS application is removed and reinstall

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.

When is "storage almost full" triggered on IOS

I have an app which uses a lot of the sandbox cache temporarily. I would like to prevent the OS from triggering the "storage almost full" warning by not filling up the disk beyond the trigger point.
I cannot find documentation on how this level is set.
Is it configurable for the user ? Is it unique to the device or IOS version ?
Update:
There is a solution available for this in Apple Developer Forum.
log out of itunes store in settings, wait 10 minutes, then log back
in. your storage should go back to what it should have been all
along. there is an itunes media caching bug / storage leak in ios 8
(all versions so far)
Original answer:
As far as I know there is no warning like that in iOS.
You can use as much as space available in the device, there is no limitation for that. Also those cache files are temporary, it'll be automatically cleaned.

iOS deleting all app sandbox data automatically

I have a very strange issue that has been occurring to a few users of my app. One of the users actually described the issue to me.
My app downloads magazine data to the device to allow for offline reading. This means that users can sometimes have around 10 gigs+ downloaded to the device.
The problem this user experienced (and a few others have too) is that randomly all sandbox data gets deleted from the app (included core data files). The user told me that he was downloading something in a different app and got the "Storage Almost Full - You can manage your storage in Settings" popup message.
He went to the settings app and went to General > Usage. He then saw the app was using around 13 gigs of data. While he was in that list he said every time he went out of the Usage tab, then back in the app's data was getting smaller and smaller. Until eventually the app said it was using 0mb.
When he logged back into the app all his data was deleted and core data was also removed which lead the app to think he was a completely new user with no data downloaded.
I then ran some tests on my own where I made sure my device only had 100mb of space available. I then started downloading in the app. The warning message popped up alerting me I was running out of space and I ignored it and continued downloading. I have now downloaded about 1.5 gigs of data and am still downloading and the device seems like it is freeing up space somewhere else to make room for my downloads.
I've searched far and wide and have found no one else ever experiencing a problem like this. So my questions are:
Has anyone else every experienced this issue before?
Does Apple have a policy that will remove app data from the app that uses the most space if the device is running out of space?
Is there an algorythm that decides which app will get cleared when space is running out?
Is there a way to tell the OS not to remove data when running out of space?
Any help would be appreciated!
Assuming you're storing the data in the caches subdirectory:
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.
Documentation here

When does iPad clear library/caches?

In response to Apple's changes in iOS data storage guidelines I recently reconfigured an iPad app to store its documents (50MB+) in the library/caches folder.
During testing in the iOS simulator I didn't see any problems with this cache when I simulated an update (following Brad Larsson's suggestion). I also tried deleting all of the contents of the library/caches folder to make sure that my app could recover.
However, when I released the app upgrade I found that my users complained of problems that were traced back to the iPad partially deleting this cache. It seemed like sub-folder structure was at least partially left intact, but sub-folder contents were deleted.
I've redesigned the app to deal with this situation during an upgrade, but I'm worried about what will happen when the iPad decides to clear the library/caches.
Does anyone have any experience or insight into the time when the iPad would try and delete items in this cache?
Thanks
There is no 100% clear answer to this question, because Apples iOS Data Storage Guidelines are very vague … They don't explain in which cases iOS 5 will delete data inside the cache dir …
In most cases iOS starts to kill files when it's getting low on disc space, but sometimes my app lost data for no good reason. So I had do implement some kind of recovery modus to redownload/-generate files the app needs.
This article is interesting: http://iphoneincubator.com/blog/data-management/local-file-storage-in-ios-5
The documentation states the following:
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.
The part about it never occuring while the app is running is crucial for our app, and is a really good insurance that we won't get unexpected behaviour.

Resources