Yes, it is ok to use the cache from the target of the branch (master) to start the analysis of the branch itself. Ins such the result for all files that were not changed will be reused. However, once the analysis on the branch will be finished, the whole directory will be overridden with the new cache context. So the branch cache should not be written back to the master.
So there are few options for branch analysis:
Always using master branch cache on a branch, and never uploading it
Having a separate branch cache that is read/write by analysis of the branch, and using a master cache when the branch cache wasn’t created yet.
As a note, with the latest version of the SonarQube (9.4) we performed some optimizations that have drastically reduced the size of the analysis caches, which may make branch caches more viable.
This leads us to the question regarding collisions:
the same directory on the same machine should not be used for multiple concurrent analysis
for the upload of the cache, the read/write is more relevant to the caching mechanism that you use on the CI, the analyzer expect cache to be stored locally on disc