3

In the past, I put temp files in /tmp/ folder, and the OS automatically purges them as time goes by.

I'm now considering using the alternative folder /Users/username/Library/Caches/myFolder/ but before I do, I want to make sure that it won't fill-up the user's disk. Will the OS automatically delete older files in that folder?

4
  • I wouldn't use this as a 'scratch' space for your own temporary files. At best, I would suggest you create a ~/Temporary folder and put your stuff in their. You could even create a launchd script to manage the contents. – benwiggy Jun 24 '20 at 17:16
  • @benwiggy Temportary files should fo in the place the OS provides for them - ie the directory pointed to by the environment variable TMPDIR or if programming in Objective C from the call NSTemporaryDirectory() - or better use a call to create a temp file – mmmmmm Jun 24 '20 at 17:28
  • Files in /tmp/ are deleted at each reboot. See also superuser.com/questions/187071/… – lhf Jun 24 '20 at 17:35
  • @mmmmmm I agree if the OP is programming. But if it's just "some files that I only need for a bit", that's different. – benwiggy Jun 24 '20 at 20:05
5

In my mind, Caches should not be cleaned by an OS.

In general, the process that generates the cache is responsible for always working - if the cache is missing it should recreate it, it should run periodically and clean the cache or expire old data. Each cache should exist for specific reasons, triggers and expirations so a routine clean up imposed by any OS uniformly on all caches would be a bad design depiction and constrain the usefulness of caches in general.

In specific don’t see macOS ever cleaning ~/Library or /Library cache folders either. I can’t be sure it’s not cleaning at a time I don’t see or just leaving my stuff there alone. There could be low disk space triggers that do clean there and I just don’t run my machines to trigger that occasional cleanup or emergency cleanup if the OS is about to run out of all space.

There are triggers where the OS will just kill running processes when there is no memory, so only Apple could tell you if they have any circumstances where this would be cleaned.

0

I think the answer is at https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW11

It suggests that the OS does not periodically clear files in the cache folder. But the OS "may" clear files in the "temp" folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .