Command Palette

Search for a command to run...

Hectal
Phase 10: Security and Privacy (Defensive)
RAG and Vector Search · Exercise 5 of 6 PreviousNext
Intermediate

A cache that cannot cross tenants

Write cached_answer(cache, tenant, question, search). cache is a dict, and search(tenant, question) returns the answer text.

Build the key from the tenant and the question's lower-case words joined by single spaces (use re.findall(r"[a-z0-9]+", ...)), separated by a bar. If the key is not in cache, call search once and store the result. Return the answer.

What Check tests

  1. The same tenant and question search once
  2. Different tenants never share an answer
  3. Capitalisation and punctuation do not matter
  4. The tenant is part of the key

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.