So, you can pedal at 90rpm (revolutions per minute) at 145bpm(heart beats a minute) or you can pedal 90rpm at 165-170bpm depending on the resistance you are meeting at that Rpm.
You want to have a high cadence, at a heart rate that you can sustain for hours. You are ultimately trying to stay right below the lactic threshold (the point were you muscles can't get rid of the lactic acid quick enough and you legs start to really burn and fatigue)
So when you're going through the terrain, keep your legs pumping at a decent cadence (rpm) and get your heart rate where you want it once you're warmed up. If you're looking to increase you're cardio, then you want to stay right below that lactic threshold for a sustained period of time (at least 20-25 minutes, all the way up to hours, depending on your capabilities...and remember, you're always capable of more than you think but also listen to your body on rest days to tell you how hard you really trained the days before. That's a good indication of how hard you we're pushing it. Your muscles will feel sore the next day if you get your body too hot and keep a high heart rate for too long in your work out) it's good to be a little sore and ride through it the next day. You reach that threshold faster at a higher heart rate. Or you want to vary your resistance from a nice pace to all out pushing it for one minute (or however long you can sustain it before fatiguing) back to a sustainable pace for 5 minutes and push it again. Do that back and forth for 25-35 minute (5 minute warm up and cool down) and then longer as you gain your cardio.
Think of your warm up like warming up your car. When the car is cold, it runs at higher rpm's until you let it sit and warm up and those rpm's drop. (But the engine when idling is putting out the same resistance. The rpm's just drop down because it's getting warm and the fluids thin)
And think about your gearing just like a car. You can go 20mph at 2000rpm or you can go 20mph at 4500rpm depending on what gear you're in. if you're in too low of a gear, you'll be going 20mph and your car will be redlining (think lactic acid threshold) if you're going 20mph in too high of a gear, you'll be bogging down and need to go faster (cadence) so your engine(muscles) doesn't have to work so hard to keep up that speed(also will hit your lactic acid threshold.) This is were you're gearing on your bike comes into play. As you're riding through this hilly terrain, you need to be using those gears to keep you at a continuos rpm and a continuos effort. Your speed will vary but your rpm and energy output won't. So you might be coming to a slight uphill and you need to drop down one gear or you come to a bigger hill and you need to drop down 5 gears (or even switch down to 2nd gear on the from derailer) so that your effort and cadence are the same but your speed will drop. Just like when you are going downhill, your effort should be the same. you might have to switch into bigger gears to keep up your cadence but your effort will stay the same and your speed will increase.
I hope this makes sense. I'm trying to be as clear as possible when it comes to heart rate/cadence and effort/lactic threshold and using your gearing.