For years, scientists have traced a link between coffee drinking and heart health, but they weren't sure exactly why coffee was associated with so many health benefits.

A group of German researchers thinks it has found a possible answer, and it has to do with how the cells in our blood vessels react to caffeine.

The researchers think the caffeine level required for optimal heart health is about four shots' worth of espresso a day, though everyone's caffeine concentrations will be a little different.

But don't overdo it.

Four cups of strong coffee a day might be the recipe for a healthy heart, especially for older adults.

A team of German researchers, led by the molecular biologists Judith Haendeler and Joachim Altschmied, thinks it has discovered clues about how coffee works its caffeine-fueled magic on our heart health and how much caffeine we should drink each day to see the best benefits.

By studying caffeinated lab mice and dosing human tissues with caffeine, the researchers discovered how a jolt of the stimulant could improve the way cells inside our blood vessels work — essentially, by making certain proteins inside older adult cells perform more like young and nimble ones. The study was published Thursday in the journal PLOS Biology.

"When you drink four to five cups of espresso," Altschmied told Business Insider, "that seems to improve the function of the powerhouses of our cells, and therefore seems to be protective."

Scientists have for years noticed that people who drink coffee seem to be less likely to die from all sorts of causes, including heart disease, stroke, or diabetes. Perhaps the best evidence yet for this comes from two massive studies: one of more than 400,000 people in the US by the National Institutes of Health, and another of more than 500,000 Europeans. Both studies found that regular coffee drinkers were less likely to die from any cause than people who don't sip a daily brew.

Coffee is also associated with a whole host of other health benefits, including a lower risk of liver disease (cirrhosis), a lower risk of developing certain kinds of cancer, lower rates of dementia and Alzheimer's, and a reduced risk of depression. It's also great for your heart — people who drink three or four cups a day may be 19% less likely to die from cardiovascular disease.

Altschmied said he hoped his new study would debunk the old advice that people with heart problems shouldn't drink coffee, and he argues that drinking the equivalent of about four shots of espresso a day could help reduce the risk of heart attacks, especially for people who are obese or prediabetic.

"It will not replace other things," he said. "Keep on doing your sports, eat healthy, and add coffee to your diet."

If you don't like the taste, green tea has similar levels of caffeine and could also be an effective way to boost heart health.

It's important not to overdo it with the new recommendation, as too much coffee can quicken your heartbeat and cause other health problems. But drinking up to six cups a day should be OK, cardiologists say, and may even reduce arrhythmias in people with irregular heartbeats.

One caveat: The study wasn't done in humans — only in human tissues and lab mice. What works in a hypercontrolled environment of mice, dosed with very specific amounts of caffeine, may not be the same as what happens when you drink a cup of joe at home.

"If I had four cups of espresso and you had four cups of espresso, we cannot guarantee that we reach the same level in the blood," Altschmied said.

He also offers a word of caution: Because caffeine can make blood vessels grow, providing more oxygen to fuel tumors, the coffee-drinking advice might not hold for people who have cancer.

"Where people have a diagnosed tumor, we would say better take your hands off the coffee," Altschmied said. "But if you're otherwise healthy, it will not harm you, and it might help your heart and circulatory system stay better functional for a longer time."