If you have downloaded the engine from the Launcher, then you have to edit [UE4_ROOT]\Engine\Config\BaseEngine.ini
Find the [InstalledDerivedDataBackendGraph] section, then find this line in it:
Local=(Type=FileSystem, ReadOnly=false, Clean=false, Flush=false, PurgeTransient=true, DeleteUnused=true, UnusedFileAge=34, FoldersToClean=-1, Path=“%ENGINEVERSIONAGNOSTICUSERDIR%DerivedDataCache”)
As you can see, the “Path” parameters tells the engine where to save DDC. By default it’s in AppData folder. So just replace it with any path you want (the path can be relative or absolute)
Note, that I haven’t tested this method myself!
If you compiled the engine from GitHub source then just create an environment variable UE-LocalDataCachePath and set the path as it’s value. Keep in mind, that in this case it will change the DDC directory for all compiled versions of the engine you have. This should work - I tested it.