Library/Caches for app groups: automatically deleted when needed ?

In an app we can use FileManager.SearchPathDirectory.cachesDirectory (objc:NSCachesDirectory) to store files that could be recreated if necessary (and will be automatically deleted by iOS in cases of low disk memory).

For app groups, there is a shared location that is automatically created as soon as we use containerURL(forSecurityApplicationGroupIdentifier:) (objc:containerURLForSecurityApplicationGroupIdentifier) :

Library/Caches

  • Is this cache directory (created by iOS) also gets automatically deleted by iOS in cases of low disk memory ?

I also have more related questions :

  • does this cache directory size count in the used disk space by the app displayed in the settings app ?
  • is this cache directory (and same question for the top containerURL directory) saved in the cloud backups ?

Does anyone have any information about this?

Answered by DTS Engineer in 792228022

FYI, most of the questions below are answered in "Optimizing Your App’s Data for iCloud Backup", which also includes some additional details and code snippets.

Is this cache directory (created by iOS) also gets automatically deleted by iOS in cases of low disk memory ?

Yes though, to be clear, we delete the contents of "Caches", not the directory itself. This is also true of "tmp", the other directory we purge.

does this cache directory size count in the used disk space by the app displayed in the settings app ?

I don't believe so.

is this cache directory... saved in the cloud backups ?

No. Both "Caches" and "tmp" are excluded from backups by the the system.

(and same question for the top containerURL directory)

Yes. The system should be backing up all of your apps data containers. More specifically, it should be backing up all of your apps data unless:

-It's in "Caches" or "tmp" (see earlier point).

-It's been explicitly excluded from the backup.

-It's already stored in iCloud Drive (and would thus be retrieved from there).

__ Kevin Elliott
DTS Engineer, CoreOS/Hardware

Accepted Answer

FYI, most of the questions below are answered in "Optimizing Your App’s Data for iCloud Backup", which also includes some additional details and code snippets.

Is this cache directory (created by iOS) also gets automatically deleted by iOS in cases of low disk memory ?

Yes though, to be clear, we delete the contents of "Caches", not the directory itself. This is also true of "tmp", the other directory we purge.

does this cache directory size count in the used disk space by the app displayed in the settings app ?

I don't believe so.

is this cache directory... saved in the cloud backups ?

No. Both "Caches" and "tmp" are excluded from backups by the the system.

(and same question for the top containerURL directory)

Yes. The system should be backing up all of your apps data containers. More specifically, it should be backing up all of your apps data unless:

-It's in "Caches" or "tmp" (see earlier point).

-It's been explicitly excluded from the backup.

-It's already stored in iCloud Drive (and would thus be retrieved from there).

__ Kevin Elliott
DTS Engineer, CoreOS/Hardware

Thank you!

Just to be sure, can you confirm that you are talking about the directory for app groups created by appending "Library/Caches" to containerURL(forSecurityApplicationGroupIdentifier:) and not the NSCachesDirectory.

I'm asking this, because :

Just to be sure, can you confirm that you are talking about the directory for app groups created by appending "Library/Caches" to containerURL(forSecurityApplicationGroupIdentifier:) and not the NSCachesDirectory.

Yes, with one qualifier:

I'm asking this, because :

I don't see any mention of a "tmp" directory in containerURL(forSecurityApplicationGroupIdentifier:)

I reviewed our code again just to make sure I hadn't overlooked something and, on a relatively brief scan, I'm not sure how exactly tmp purging will play out. CacheDelete can purge "tmp", but I'm not sure exactly when purging would occur if "Caches" happened to be empty at the time of scan. Keeping things simple, I would recommend just using "Caches".

the link you are referring to seems to talk about the app container and not the app groups container

You're right and I just filed a bug about making this more explicit (r.130429249). We've rewritten that document multiple times (it originated as QA1719 for iOS 5) trying to find the "right" way to explain these details and app containers have just never "come up" in that conversation.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Perfect, thanks for your answers.

I'll be using the Caches subdirectory. It is great to be able to be able to share the cache between the app and the different app extensions.

Library/Caches for app groups: automatically deleted when needed ?
 
 
Q