5. You want to cache user profile data in Redis but ensure it updates if the user changes their info. Which caching pattern is best?
hard
A. Set key with expiration and delete key on user update
B. Set key without expiration and never delete it
C. Set key with very long expiration and ignore updates
D. Do not cache user data at all
Solution
Step 1: Understand caching with data freshness
To keep data fresh, cache keys should expire and be deleted when data changes.
Step 2: Evaluate options for update handling
Set key with expiration and delete key on user update uses expiration and deletes key on update, ensuring fresh data. Others risk stale data or no caching.
Final Answer:
Set key with expiration and delete key on user update -> Option A
Quick Check:
Expire + delete on update keeps cache fresh [OK]
Hint: Expire keys and delete on update to keep cache fresh [OK]
Common Mistakes:
Not deleting keys on data change
Using no expiration causing stale cache
Avoiding caching user data unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.