Avoid the spawn cache if executing dynamically.

Fixes bazelbuild#12364 (caused by https://github.com/bazelbuild/bazel/commit/25e58ffc529b9cf4e1d0dccbbad27f40f092f1ec) based on Ulf's approach, but avoiding secretly disabling some potential caches that should not be disabled.

RELNOTES: n/a
PiperOrigin-RevId: 341588598
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java
index e72c04e..51a1d65 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java
@@ -342,4 +342,9 @@
   private static boolean useDiskCache(RemoteOptions options) {
     return options.diskCache != null && !options.diskCache.isEmpty();
   }
+
+  @Override
+  public boolean usefulInDynamicExecution() {
+    return false;
+  }
 }