NSCachesDirectory
Also known as: caches directory ios, library caches
NSCachesDirectory is the search-path constant for an iOS app's Library/Caches folder, where apps store regenerable data like downloaded images and computed files. Its contents are purgeable: iOS can delete them under low-storage pressure, and they are excluded from iCloud and iTunes backups.
- NSCachesDirectory resolves to Library/Caches inside the app sandbox.
- Its contents are excluded from iCloud and computer backups.
- iOS can purge Caches automatically under low-storage pressure, usually while the app is idle.
What NSCachesDirectory is
NSCachesDirectory is a FileManager.SearchPathDirectory constant that resolves to <app sandbox>/Library/Caches. Apps obtain the URL with FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask). The folder is meant for data the app can recreate, such as thumbnails, decoded media, and network downloads.
Unlike Documents, the Caches folder is not backed up to iCloud or a computer. Apple's guidance is that anything which would be inconvenient (but not impossible) to lose belongs here, keeping backups small and fast.
Purgeable behavior and cleanup
iOS treats Caches as purgeable space: when device storage runs low, the system can delete files from any app's Caches folder, typically when that app is not running. Apps must therefore handle missing cached files gracefully and regenerate them on demand.
Because the system only purges under pressure and may not reclaim everything, this folder is a primary target for an in-app cleaner. An app can enumerate Library/Caches with FileManager and call removeItem(at:) to clear its own cache immediately, reporting the freed bytes to the user. Apps cannot delete other apps' Caches; only the system does that.