For items I think have unlimited shelf life; salt, liquor, paper and plastic: when a brand I like goes on sale I'll buy enough to last a couple years or more.
Items with limited but long shelf life; whole canned tomatoes, all purpose flour, dried whole kernel corn, green coffee beans, vinegars etc.: I'll stock up on well before they run out but try to limit the quantity on hand to a one year supply.
Whole grain flours, spices, seeds, nuts, and olive oil: I try to replace just before I run out without worrying about if they're on sale.
By far, most of my grocery shopping is done in the produce, dairy and meat & fish sections of the store.