The first thing I do when I start to cramp is to drink a lot of water ... at the first little twinges.
I know the jury is out about what causes cramps, but for me, if I am not adequately hydrated, I cramp. Usually it's my feet. And this can be just walking around, nothing to do with cycling. But if I drink a glass of water ... the cramps are gone.