Post not yet marked as solved
Post marked as unsolved with 2 replies, 1,725 views
I want to use URLCache to make data (e.g. User, Session, Privileges objects) available when offline. I think it is better to manually saving data in file or UserDefaults because it will fit seamlessly with existing code that load stuff from URLs and without extra code.
One of my concern is this. In URLCache documentation - https://developer.apple.com/documentation/foundation/urlcache, it says:
Note
In iOS, the on-disk cache may be purged when the system runs low on disk space, but only when your app is not running. I don't want my on-disk cache to get purged on low disk space.
I browse around and see URLCache has a new initializer in iOS 13 that accepts a directory url for on-disk cache.
convenience init(memoryCapacity: Int, diskCapacity: Int, directory: URL? = nil)
From my understanding, Caches directory gets purged on low disk space.
From File System Programming Guide - https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html:
In 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, be aware that restoring from backup is not necessarily the only condition under which the Caches directory can be erased. So, my question is, if I pass a URL that is not a Caches directory URL. Will my on-disk cache survive the low memory purge? If not, is there any other way to achieve it?