Smucker's hiked peanut butter and jelly prices earlier this year, and the results have investors salivating.

The Smucker brand is known for PB&J, but it also owns Folgers, sells Dunkin' Donuts-branded coffee at grocery stores and has a number of pet food lines, including Meow Mix and 9 Lives.

As coffee prices soared last year, Smucker had difficulty raising bean prices in a competitive market. So it instead hiked prices on Jif and Smucker's-brand jellies, jams and peanut butters around 6% in January.

The gamble paid off. Sales grew 1% last quarter, and profit in its consumer food division was up 10%. That offset an 18% decline in coffee earnings.

There's more buzz-worthy news: Coffee has been steadily getting cheaper. Its price has fallen more than 20% over the past year. That's a trend Smucker's Chief Financial Officer Mark Belgya said he expects to continue into 2018.

That was enough to send Smucker's (SJM) stock up 10% Thursday.

Related: Your morning cup of coffee will get more expensive

Smucker's got burned in the past when boosting coffee prices.

When it raised coffee prices by nearly 10% in the summer of 2014, due to higher commodity costs, it had to scale back after conceding that the price hikes were too aggressive.

Mark Smucker, president of U.S. retail coffee for the firm, said the company "wouldn't rip the Band-Aid off as quickly again in the future" if commodity prices rose again.

But it did.

When the company reported in August, the head of Smucker's coffee and U.S. food and beverage businesses said coffee prices were "out of line" and lowered prices again.

Smucker isn't the only company to take advantage of lowered Arabic coffee costs. Starbucks raised their prices on higher commodity costs in 2016, but it hasn't lowered them. When coffee prices fell, Starbucks continued to cite "rising costs" for keeping prices at their elevated levels.