How can I measure cadence without attaching anything to the bike?
The RPM Cadence Sensor from Wahoo can track your cadence based on the motion of your foot. On the product page it specifically mentions the following

The RPM can be worn on your shoe for spin classes or use with multiple bikes

Here's an article explaining how it can be used to track your GPS usage.  It's important that it is mounted in the correct orientation.
I'm not sure if there are any other cadence sensors on the market that work solely off of motion as opposed to the traditional magnet based sensors.
EDIT:
I found that Garmin makes some accelerometer based candence and speed sensors that attach using rubber bands.
Here is a similar product from Saris
I found that the best way to find these products is search for &quot;magnetless cadence sensor&quot;.