Well deleted the music app. It still showed using 1Gb “documents and data”.
Restarted iPhone, still showed in settings>iPhone storage and the app wasn’t there but still showed using 1Gb.
Reinstalled music app, and is still using 1Gb+ with no downloaded music….
Documents and Data include everything outside of the app bundle. This includes their /tmp and /caches folders.
Cache data is to improve system, network and battery performance plus minimize wear on the flash from writes due to repeating data and remove issues caused by flakey network conditions.
Apps determine what and how much they cache. The apps themselves will tend to only replaced cache data with new cached data. Its rare that an app will delete its own cache without a good reason. Free storage space = wasted storage space.
iOS can also purge an apps cached data. This is only done if it detects a low storage condition though. And even then it tries to be smart about it. Apps you haven't used in a while for example. Randomly deleting something that will likely be cached again in an hour isn't beneficial to the system.
Usually anything streamed at a fix bitrate will just be cached incase you want to play it again. Since there is no difference in streaming and downloading a fixed bitrate there is no reason to immediately toss it once you play it. If you end up playing it again iOS doesn't need redownload the track, lyrics, artwork etc and rewrite them to the flash, it just replays the first copy.
The algorithms apps replace their cached data falls entirely up to them. A music app might look at play count and only overwrite the songs with 1 play in the last 30 days avoiding to remove the song you listen to 5 times a day. A podcasts app might cache an entire playlist on wifi while charging. Apple apps can adjust their storage footprint dynamically as well so instead of 2gb of music they will retain 1gb in cache.
Meanwhile many web based apps will cache their normal assets since they are used every single time you use the app. For example downloading the facebook logo and page layout 50 times a day isn't a smart use of data.
As far as performance goes, 10GB is MORE than enough free storage for an iPhone. You only start seeing performance issues caused by flash storage when its around ~1gb or less. This is because iOS is constantly trying to make space while you are still receiving data and using apps that are writing temp and cache files.