Complete the code to import the FastAPI cache dependency.
from fastapi import FastAPI from fastapi_cache import [1] app = FastAPI()
The correct import for FastAPI caching is FastAPICache from fastapi_cache.
Complete the code to set up an in-memory cache backend.
from fastapi_cache.backends.inmemory import [1] cache_backend = [1]()
The in-memory backend class is called InMemoryBackend.
Fix the error in the cache decorator to set expiration time to 60 seconds.
@app.get('/items') @cache(expire=[1]) async def get_items(): return ['apple', 'banana']
The expire parameter expects an integer number of seconds, so 60 without quotes is correct.
Fill both blanks to initialize the cache with the backend and FastAPI app.
from fastapi_cache import FastAPICache FastAPICache.[1](cache_backend, prefix=[2])
Use init to initialize the cache and set a prefix string like "cache".
Fill all three blanks to create a cached endpoint with a 120-second expiration.
@app.get('/data') @FastAPICache.[1](expire=[2]) async def get_data(): return [3]
The decorator is cache, expiration is 120 seconds, and the function returns a list of data.
