Skip to content

Clear the iTunes Apple Music Cache on macOS and Windows

I love listening to music and have been a happy Apple Music subscriber since it was first released in 2015. Having access to 30 million songs is great even if I mostly just listen to the ones in the “Hard Rock” category (current favorite song: You Don’t Know by Kobra and the Lotus). Unlike some other streaming services, when you listen to a song with iTunes that has not been downloaded to your computer, it does not technically stream it while it’s playing. Instead iTunes downloads the full song to a cache folder and plays it locally from there. This has the advantage of there being fewer stutters as the song is playing, but does mean it takes a moment before the song starts playing the first time. Subsequent plays of the same song are instant, though, since it doesn’t have to download it again which may also save you some Internet data usage. A notable downside to this design is that it also means that these songs are using up space on your drive and with today’s smaller SSDs often every bit of space counts. It doesn’t appear that this space is ever cleared by iTunes, either.

These songs files are saved in a cache folder buried in hidden folders on macOS and Windows, which you can get to manually if you are comfortable with the command line.

Alternatively, you can easily make a quick Xojo app to do it for you.

For those that just want the app and don’t want to see how it’s made, you can download for macOS or Windows and use it to free up some space on your drive:

Note: The app is not code-signed, so you’ll need to run it by holding down Control on macOS. On Windows, you’ll want to click Yes on the “unknown publisher” dialog.

Running this tool cleaned up over 6GB of space on my drive.

Read on to learn a bit about how this app was made:

Making the App

This app is a Xojo cross-platform desktop project, built for Windows and macOS. The project itself is mainly just a single window with 3 controls: 2 labels and a button.

When the app starts, the Open event handler for the Window is called. This calls the SetCacheSize method, which does the following:

  • determine the cache folder location (macOS vs. Windows)
  • calculate the size of the cache folder
  • display the size in MB

Clicking the button to clear the cache space calls the Action event handler of the button, which itself calls the ClearCache method and that works like this:

  • determines the cache folder location (macOS vs. Windows)
  • deletes the files in the cache folder
  • displays a message
  • refreshes the label with the size of the cache folder (it ought to drop to 0)

Most of the code is pretty simple, but there are two methods that are a bit more involved. The first is the DeleteEntireFolder method. This method (copied directly from the FolderItem.Delete doc page) recursively deletes all files and folders in the specified folder.

The second is the FolderSize method, which is basically just a simplified version of the DeleteEntireFolder method that instead of deleting files, calculates the sum of their sizes.

If you’d like to look at (and maybe modify) the project yourself, you can download Xojo for free and then download the ClearAppleMusicCache project. Open the project with Xojo and click on the various project items to view the layout and code. Click the Run button to try it out.

I hope this helps you free up some space on your computer while you enjoy your music.