I prefer to remove the cassette from the wheel for a thorough cleaning. To quick clean a reasonably clean cassette I use a cloth folded in half which I spray with WD40...it is NOT a lubricant...to wet but not dripping and slide it back and forth between the cogs to clean. Refold to a clean area of the cloth as needed. But nothing compares to removing it for a thorough cleaning...to the wheel as well.
You certainly do not want to contaminate the rotor or pads.