🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Caching and CDNs: all 10 questions

Quiz: Caching and CDNs · Question 7 of 10

What does this print? (code)

What does this print?

cache = {}
db = {"course:1": "Java"}
hits = misses = 0
for key in ["course:1", "course:1", "course:1"]:
    if key in cache:
        hits += 1
    else:
        misses += 1
        cache[key] = db[key]
print(hits, misses)
  1. A.0 3
  2. B.3 0
  3. C.1 2
  4. D.2 1
Answer & explanation

Correct answer: 2 1

The first read misses and fills the cache; the next two are hits.

Can you get the rest right without peeking?

Take the timed Quiz: Caching and CDNs quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →