Exercise 3: Why recipe_cache Is Keyed by Ingredient — Possible Solution ==================================================================== WHY NOT KEY BY THE FULL DAILY COMBINATION ------------------------------ If the cache were instead keyed by the entire combination of expiring items on a given day, a cache entry would only ever be reusable on a day with the exact same set of expiring ingredients - an extremely unlikely coincidence, since the specific mix of what's expiring changes constantly from day to day. Almost every day's combination would be a cache miss, making the cache barely useful at all in practice. THE BENEFIT OF KEYING BY INGREDIENT INSTEAD ------------------------------ Keyed by individual ingredient, a cached "chicken" lookup gets reused any time chicken appears in the alerts list again, regardless of what else happens to be expiring alongside it that particular day - the cache hit rate depends only on how often that one specific ingredient recurs across different days, which is far more likely than an entire day's full combination ever repeating exactly. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that keying by the full daily combination would make cache hits extremely rare since exact combinations rarely repeat, and correctly explains that keying by individual ingredient instead makes the cache genuinely reusable whenever that specific ingredient recurs on any other day, independent of what else is expiring at the same time.