For some reason I can't comment so I'm going to have to answer instead. One option (I'm not sure it will work) is to modify the file in the package cache. I believe that unless you clear it, unity will pull the files from there each refresh. Another option is to create a script that runs on project reload and overwrites the file with the version you want.
Possible ways to receive callbacks
I haven't tested these and I'm not sure if they will work, but I hope they'll be helpful to you.
EditorApplication.playModeStateChanged
IPreprocessBuildWithReport
AssetsModifiedProcessor
UnityEditor.Build
namespace
You mentioned the project reloading, so EditorApplication.projectChanged
might be of help to you as well.
These links https://answers.unity.com/questions/704066/callback-before-unity-reloads-editor-assemblies.html https://docs.unity3d.com/ScriptReference/Callbacks.DidReloadScripts.html might also provide you with enough information to solve your problem.
As a last resort, you could create your own copy of ShadowCaster2D
and
use that behaviour instead of the default one