Exercise 1: Redirecting Three Distinct Codes a Mixed Number of Times — Possible Solution ==================================================================== THE SEQUENCE ------------------------------ code_a = shortener.create_short_url('https://example.com/article-a') code_b = shortener.create_short_url('https://example.com/article-b') code_c = shortener.create_short_url('https://example.com/article-c') # 5 redirects of code_a, 3 of code_b, 10 of code_c = 18 total redirects RESULT ------------------------------ total redirects performed: 18 store_lookups (should be 3 - one genuine miss per distinct code): 3 Across 18 total redirect calls spanning three distinct short codes, store_lookups landed at exactly 3 - not 1 (this chapter's own single- code result) and not 18 (no caching at all). WHY EXACTLY 3, NOT 1 AND NOT 18 ------------------------------ CacheAsideRedirectService.cache is keyed by short_code - each DISTINCT code genuinely needs its own first real store lookup before it becomes cached, exactly like Chapter 3's own two-key PROD-1/PROD-2 exercise confirmed. code_a's first redirect is a genuine miss (lookup #1); its remaining 4 redirects are cache hits. code_b's first redirect is a second genuine miss (lookup #2); its remaining 2 are cache hits. code_c's first redirect is a third genuine miss (lookup #3); its remaining 9 are cache hits. Three distinct codes, three genuine misses, regardless of how many times each one is subsequently redirected. WHY THIS CONFIRMS THE CAPSTONE'S CACHING SCALES TO A REALISTIC WORKLOAD ------------------------------ This chapter's own original demonstration only tested one short code. A real URL shortener serves many distinct codes simultaneously, each with its own independent popularity - this exercise confirms the cache-aside layer correctly gives every distinct code its own independent caching lifecycle, with no cross-contamination between codes and no unnecessary re-fetching for codes that are already popular and cached. WHY THIS WORKS AS AN ANSWER ------------------------------ Three genuinely distinct codes are created and redirected different numbers of times using this chapter's own unmodified UrlShortener, and the resulting store_lookups count is verified directly against the specific expected value (3) with the reasoning for why it's neither of the two obvious wrong answers (1 or 18) explained precisely.