Recall & Review
beginner
What is caching in FastAPI?
Caching in FastAPI means storing data temporarily so that future requests can get the data faster without recalculating or fetching it again.
Click to reveal answer
beginner
Name two common caching strategies used in FastAPI.
Two common caching strategies are:<br>1. In-memory caching (like using Python dictionaries or libraries like cachetools).<br>2. External caching (using Redis or Memcached to store cached data).
Click to reveal answer
intermediate
What is the benefit of using Redis for caching in FastAPI?
Redis stores cached data outside the app process, allowing multiple app instances to share the cache. It is fast and supports expiration times to keep cache fresh.
Click to reveal answer
intermediate
Explain cache expiration and why it is important.
Cache expiration means setting a time limit for cached data. After this time, the cache is cleared or refreshed. It is important to avoid serving outdated data and to keep the cache size manageable.
Click to reveal answer
beginner
How can you implement simple in-memory caching in FastAPI?
You can use a Python dictionary to store results of expensive functions. Before computing, check if the result is in the dictionary. If yes, return it; if no, compute and save it.
Click to reveal answer
Which caching strategy allows sharing cache between multiple FastAPI app instances?
✗ Incorrect
Redis stores cache outside the app process, so multiple instances can access the same cache.
What does cache expiration help prevent?
✗ Incorrect
Cache expiration ensures cached data is refreshed to avoid outdated information.
Which Python library is commonly used for in-memory caching?
✗ Incorrect
cachetools provides easy-to-use caching decorators and data structures.
What is a downside of using only in-memory caching in FastAPI?
✗ Incorrect
In-memory cache is lost when the app process stops or restarts.
Which of these is NOT a caching strategy?
✗ Incorrect
Database indexing improves query speed but is not a caching strategy.
Describe how you would add caching to a FastAPI endpoint to improve performance.
Think about storing results and reusing them for future requests.
You got /4 concepts.
Explain the difference between in-memory caching and external caching in FastAPI.
Consider where the cache lives and how multiple app instances access it.
You got /4 concepts.