Bird
0
0

Given this code snippet, what will be printed?

medium📝 component behavior Q4 of 15
LangChain - Production Deployment
Given this code snippet, what will be printed?
cache = InMemoryCache()
result1 = cache.get_or_set('x', lambda: 10 * 2)
result2 = cache.get_or_set('x', lambda: 5 * 5)
print(result2)
AError
B25
CNone
D20
Step-by-Step Solution
Solution:
  1. Step 1: Understand get_or_set behavior

    First call caches value 20 under key 'x'.
  2. Step 2: Second call returns cached value

    Second call ignores lambda and returns cached 20, not 25.
  3. Final Answer:

    20 -> Option D
  4. Quick Check:

    Cache returns stored value, not recomputed [OK]
Quick Trick: Cached key returns first stored value [OK]
Common Mistakes:
MISTAKES
  • Assuming second lambda runs and returns 25
  • Expecting None if key exists
  • Thinking it causes an error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes