One huge unknown issue is how long the foam sat on the shelf in storage before it was sold. It could have been part of a bulk order that was bought a decade or more ago. Unless you are buying it directly from the manufacturing plant that made it, you just don't know. Most places wouldn't junk existing inventory just because it had been sitting there for a while.
Beyond that, there are different types of foam, etc. It makes it difficult to answer your question as a generalization absent context wouldn't really be helpful.
It's been over 20 years now since I last re-foamed the woofers and passive radiators in my JBL L150 speakers, and I run them hard enough that if the foam was getting weak, it would likely fail. That's actually a longer amount of time than the original foam (that came new with the speakers) lasted.
I keep my speakers out of direct sunlight. If your foam is being exposed to direct sunlight from a window then that will destroy your foam in a very short amount of time.