Many CI systems keep a main cache for the master branch and make a copy of it when a branch/PR is created. In such common case the path should not be customised with the branch name and it can be as you wrote (C:\sonar-cache\my-driver\) because branches cache will be forked from the master branch.
Ah ok, it kind of sounds like I should do the following, can you confirm:
when master builds
cache to C:\sonar-cache\my-driver\
when other branches build
Take a copy of C:\sonar-cache\my-driver\ (say, copy to C:\vsts-agent_work\1\s\sonar-cache\my-driver)
modify the sonar.cfamily.cache.path to C:\vsts-agent_work\1\s\sonar-cache\my-driver\
run analysis.
Is this correct? That way, the copy is a throwaway, and only used during that analysis.
How about when feature branches get involved? e.g. master - cached to C:\sonar-cache\my-driver features/my-feature - analysis ran - output not cached? jl/my-addition-to-a-feature - Doing a PR from this branch to features/my-feature.
When running my CI analysis build on my PR (from jl/… to features/…), what should sonar.cfamily.cache.path be set to? Because C:\sonar-cache\my-driver\ would point to the last master run.
CI build runs, copies master build analysis, then runs incrementally, due to the files being on disk.
Is this (at least somewhat) correct?
Assumably this means I can get it working for PRs into feature branches, by caching them also and using the TargetBranch to copy the correct cache when doing the PR?