I had a similar experience on a long flight. I figured I'd avoid caffeine so I could sleep better, but I just woke up a few hours into the flight with a bad headache. Headed back to the galley to get some coffee, then slept halfway well.
Excedrin or the generic OTC "migraine" medications are good for this: a bit of caffeine, aspirin, and acetaminophen. Easier to carry around than having to scout out coffee and a bit more general purpose than caffeine pills alone.