slushy
slushy

Reputation: 12385

Should we not avoid manually purging iOS tmp and Caches folders?

Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.

https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

There are conflicting answers about the need to manually clear the tmp folder. There is no API for clearing it, it must be performed manually file by file (which says something). More importantly, we should always avoid unnecessarily overworking the disk because it will wear out the SSD (Apple's Data Storage Guidelines mentions this also), and purging a folder file by file that's designed to be purged by the OS routinely seems counterintuitive.

  1. Would it not be best practice then to delete what we know for certain isn't needed anymore as it comes our way (on-the-spot cleaning) and let the rest be purged by the OS and avoid manual purging altogether?

  2. And should we not apply this strategy to the Library/Caches folder as well, since that folder's cleaning policy is the same as the tmp folder's?

Upvotes: 2

Views: 149

Answers (1)

Rob
Rob

Reputation: 437452

You said:

  1. Would it not be best practice then to delete what we know for certain isn't needed anymore as it comes our way (on-the-spot cleaning) and let the rest be purged by the OS and avoid manual purging altogether?

Yes, the documentation is telling you that when you create a temporary file, that you should just remove it as soon as you’re done with it. There’s no “manual purging” or sweeping of this folder needed. Just delete the individual files when you’re done with them.

  1. And should we not apply this strategy to the Library/Caches folder as well, since that folder's cleaning policy is the same as the tmp folder’s?

If you know for certainty that you don’t need a particular cached file anymore, then absolutely delete it.

But often with caches, you don’t know when a particular file isn’t needed anymore, so we often resort to LRU-style logic based up the quantity, size, or cost of the assets.

But in both cases, you want to clean up as appropriate, to prevent unbridled growth in storage. You want to avoid using persistent storage for assets that are no longer needed

Upvotes: 1

Related Questions