Want to make a million dollars? Find a way to stop cramping that holds up to scientific scrutiny. So far, no one has done it. That means all you can do is try every solution you can find and see if it works for YOU, knowing that it may be useless for everyone else.
For me, it was a combination of getting in better shape, stopping taking statins, and getting my body keto adjusted, so that my carbs come from fat stores rather than carbs. I also drink on average 1 bottle of water an hour with those 0 carb electrolyte replacement tablets.
I still cramp up occasionally, but only after the ride, almost never during the ride.