The hardware usually manages cache coherency and there are many different strategies to ensuring caches are consistent.
If you're interested in this (warning: This is a deep rabbit hole), then I suggest this as a good starting point:
A Primer on Memory Consistency and Cache Coherence, Second Edition
https://www.morganclaypool.com/doi/abs/10.2200/S00962ED2V01Y201910CAC049
How is cache coherency handled?