Is there a way to set the disk caching behavior on macOS?

Yellow memory pressure is not in itself an indication of any sort of "problem" with your system.

If that is the only "negative" indication in Activity Monitor, then getting rid of cached files from memory won't help performance of your system. Rather the opposite.

Take a look at "Swap used" in Activity Monitor - if this is "0 bytes", then the system has the RAM it needs, and getting rid of cached files won't mean that the now freed memory can be used for something that would somehow speed up your system.

However, if your "Swap used" is a significant amount, it might be that getting rid of cached files could speed up your system. It doesn't mean that in every case though. What matters is whether the swapped out data is something the system actually needs now. If that is the case, you can check the amount of data swapped in/out per second (or minute or similar) to see if the system is actively swapping in/out data while you are experiencing problems with your workload.

If you do indeed convince yourself that changing the disk caching behavior is necessary, you can use the sysctl command in the Terminal to do so.

You can list all the possible settings using sysctl -a - especially the ones that have "vm" in the name are be interesting here. I would take a look at the following settings:

  kern.vm_page_free_min
  kern.vm_page_free_target
  kern.vm_page_free_reserved
  kern.vm_page_speculative_percentage
  vm.vm_page_background_mode
  vm.vm_page_background_target

You can see their current setting like this:

sysctl kern.vm_page_free_min

And set a new value with:

sysctl kern.vm_page_free_min=250000

Note that the above is just a fictive example - you would need to supply your own value.