Bird
0
0

What will be the output of this code?

medium📝 component behavior Q5 of 15
LangChain - Production Deployment
What will be the output of this code?
cache = InMemoryCache()
cache.get_or_set('a', lambda: 'hello')
cache.get_or_set('b', lambda: 'world')
print(cache.get_or_set('a', lambda: 'new'))
Aworld
Bnew
Chello
DError
Step-by-Step Solution
Solution:
  1. Step 1: Cache stores 'hello' under key 'a'

    First call caches 'hello' for 'a'.
  2. Step 2: Second call caches 'world' under 'b'

    Third call returns cached 'hello' for 'a', ignoring lambda.
  3. Final Answer:

    hello -> Option C
  4. Quick Check:

    Cache returns first stored value for key [OK]
Quick Trick: Cache returns original stored value for repeated keys [OK]
Common Mistakes:
MISTAKES
  • Expecting 'new' to replace cached value
  • Confusing keys 'a' and 'b'
  • Thinking it prints 'world'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes