Bird
0
0

You want to cache results of a function that takes a list as input. Which approach correctly enables caching?

hard📝 Application Q8 of 15
Agentic AI - Production Agent Architecture

You want to cache results of a function that takes a list as input. Which approach correctly enables caching?

AStore only the last computed result without keys
BUse the list directly as a cache key
CClear the cache after every call
DConvert the list to a tuple before using it as a cache key
Step-by-Step Solution
Solution:
  1. Step 1: Understand cache key requirements

    Cache keys must be immutable and hashable.
  2. Step 2: Identify list mutability issue

    Lists are mutable and cannot be used as keys directly.
  3. Step 3: Convert list to tuple

    Tuples are immutable and hashable, suitable as keys.
  4. Final Answer:

    Convert the list to a tuple before using it as a cache key -> Option D
  5. Quick Check:

    Immutable keys = tuple conversion [OK]
Quick Trick: Use immutable types as cache keys [OK]
Common Mistakes:
  • Using mutable lists as keys
  • Clearing cache unnecessarily
  • Not using keys for caching

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes