Coffee drinking has been associated with a raft of health benefits in recent years - such as reducing type 2 diabetes risk and improving your liver health - and just generally making us feel more alert and awake.

But now scientists from US National Cancer Institute have found that people who drink four cups of coffee day are 20 percent less likely to develop malignant melanoma than non-coffee drinkers.

The study looked at 447,357 retirees over a period of roughly 10 years, and analysed the coffee consumption of all participants, and their diet.

During the study period, 2,904 people developed malignant melanoma (the deadly kind that's spread beyond the top layer of the skin) and 1,874 people had developed early-stage melanoma, which hasn't yet spread.

They then assessed how much UV each participant would have bee exposed to, based on NASA data on the amount of sun each person's hometown had received over the study period.

They also looked into how much they exercised, how much alcohol they drank, whether they smoked and also their body-mass index. 

When controlling for all those factors, as well as a family history of cancer, the researchers found that drinking at least four cups of caffeinated coffee a day still turned out to be significantly linked to a 20 percent reduction in malignant melanoma risk.

"Our study is the largest to date to evaluate this relationship," one of the researchers involved in the study, Erikka Loftfield, told Stephanie Pappas from Live Science.

The results have been published in the Journal of the National Cancer Institute.

 This risk reduction was only significant for caffeinated coffee, not decaff, which suggests that the benefit may be coming from caffeine, but further research needs to be done on the different compounds in coffee and how they relate to skin cancer risk.

As Alice Park reports for Time

The roasting process of coffee beans also releases vitamin derivatives that protect against UV damage in mice. There's also intriguing evidence that caffeine may act as a molecular sunscreen, absorbing UV rays and therefore protecting DNA from damage.

The team explains that their results now need to be repeated and verified. And, of course, the best way to avoid skin cancer is still to avoid UV exposure, Loftfield told Pappas. 

"Our results, and some from other recent studies, should provide reassurance to coffee consumers that drinking coffee is not a risky thing to do," she told LiveScience via email. "However, our results do not indicate that individuals should alter their coffee intake."

But this isn't the first time that coffee has been shown to have a protective effect against a type of skin cancer. Back in 2012, research found that women who drank more than three cups of coffee a day had a 21 percent reduction in basal cell carcinoma risk, compared to women who only drank one cup of coffee a month. For men, the risk reduction was 10 percent.

"Most likely, the protective effect is due to caffeine," the lead author Jiali Han, from Harvard Medical School in the US, told Anna Azvolinksy over at Scientific American at the time.

So bottom line? Keep being sunsmart, but don't feel bad about enjoying an iced latte while you do so.

And just in case you were wondering, here's when you should be drinking coffee, according to science. And, yes, you can drink too much.

Sources: Time, LiveScience, Scientific American