So, it's on sale. How much to buy?
For products with a fairly long shelf life, I buy according to the expiration date (actually "best used by" date). From today, to that date, I count the months, and buy an amount equal to that number of months. Meals are loosely planned to use that product once a month. If it's something that I would eat more often, I would buy twice as much, and plan to use it every 2 weeks.
As an example, the local WalMart has jars of Ragu 4 cheese Alfredo sauce at 1.25 each, about half the cost of most other "inexpensive" Alfredo sauces. The expiration date is 10/2024, 20 months from now. So, it's picking up about 20 jars.
And, on a side note, WalMart has had strange pricing with Ragu Alfredo sauces. A few months ago, the large 21.5 ounce jars of regular Alfredo were priced the same as the 16 ounce jars. No rollback or clearance, the original listed price, like the above 4 cheese sauce.