I chose caffeine as an example because I think that it's completely nontrivial to calculate. The physical pathways of things like "well this makes that molecule do this and have some x% chance to mutate and so on and so you get cancer", or the statistical output of "well people in the coffee cohort have % higher rates of this cancer" are much easier to accurately study than things like "if you drink coffee you are 3% more likely to get into law school and therefore become significantly wealthier and probably live a longer/healthier life and we can measure that impact precisely".
It's also not at all obvious that lifespan above all else is the thing to maximise. e.g. maybe red meat reduces lifespan but makes your 20s-60s more fun because you're likely to be more muscular or whatever.
My personal feeling is that aside from really really bad things like smoking, heavy alcohol use, heroin etc the error bars are too large to make decisions purely on long-term health impact alone.