I've had boxes of emergency rations (add hot water to get some rice meal) in our house, but they usually just advertise lasting for just a few years.
For dry / packaged goods (dried beans, lentils, pasta, rice, spices, toast, etc) you can basically ignore the best-before date. Sugar (or -syrups, honey) & salt keep indefinitely.
'Wet' stuff, as long as sealed hermetically (like canned goods, shelf-stable drinks etc): similar. Seal broken: all bets are off. Use eyes / nose / texture as indicator, or don't risk it.
Long storage of these isn't a safe-to-eat, but a quality issue. Taste, sometimes texture, and vitamin / nutritional value deteriorates over time. 'Wet' stuff generally faster. Up to a point where you're left with tasteless calories with 0 vitamin content (but still safe to eat!).
Also: say you have 5y worth of food stored. Then you'd need to replace that vast amount of food semi-regularly (like use 1y worth, give away & replace the rest), which is very costly. Or consume everything yourself (FIFO). In which case a 5y's worth store would mean eating -on average- 5y old food. Not to mention the cost/waste if that supply is somehow lost (flooding, housefire, bugs, rodents, whatever).
Imho a 1 month up to 1 or 2y supply is a better compromise. Modest space/$ investment & most stuffs can be eaten within their BB date. But enough for peace of mind or ride out a wave of economic / social mayhem. Add some vitamin pills if you're worried about fresh fruits/veggies remaining available.
I've grown my own food at times. And imho substinence farming is underrated. But as a hedge against catastrophy? No. Do it for fun, do it if you have a large garden & like your independence. Or prefer the organic-everything & knowing where your food comes from.
Otherwise just buy food in bulk & stuff it in cellar (or wherever).