Thursday, March 9, 2017

Twitter for iOS Gains New Option for Clearing Cache

Nick Heer:

None of these figures are very large individually but, collectively, I’d conservatively estimate that I have about 1 GB of cached data on my iPhone that could be purged. I wish there were a button in every app’s settings panel to dump old or expired data, but I suspect this is a lot harder than it seems: how can iOS reliably know what’s old and expired?

Every app should implement a Clear Cache feature.

1 Comment RSS · Twitter

Ben Kennedy

iOS and Mac OS both provide facilities for getting a sanctioned Caches directory, about which Apple's File System Programming Guide* states:

“Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.”

Clearly, it is within the purview of the OS to purge the Caches directories at any time. Indeed, such a button as Nick describes would presumably do so.

Moreover, though, I would argue that a decently-designed app would take reasonable care with its cache use, and be respectful and intelligent enough to purge what's out of date. We take a limited form of this approach at the app I build at my day job, which has a facility to download arbitrary file attachments from a remote server. We maintain a local cache with last-accessed time stamps, and run a periodic watchdog that evicts stale files on the basis of recent use, total cache size (limited to a hard-coded ceiling of a few hundred MB), as well as overall device free space (clamping the cache to ensure system breathing room).

* https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW28

Leave a Comment