Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the caching extension in Flask.
Flask
from flask_caching import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'CacheControl' which is unrelated to Flask-Caching.
Using 'CacheManager' which does not exist in this package.
✗ Incorrect
The correct class to import for Flask-Caching is Cache.
2fill in blank
mediumComplete the code to initialize caching with Flask app.
Flask
cache = [1](app) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong class name like 'CacheControl'.
Forgetting to pass the app instance.
✗ Incorrect
To initialize caching, create a Cache object passing the Flask app.
3fill in blank
hardFix the error in the decorator to cache the response for 60 seconds.
Flask
@cache.[1](timeout=60) def get_data(): return 'Hello, cached!'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent decorator names like 'cache_response'.
Confusing with other caching libraries.
✗ Incorrect
The correct decorator method is cached to cache the function's response.
4fill in blank
hardFill both blanks to configure Flask-Caching with simple cache type and 300 seconds timeout.
Flask
app.config['CACHE_TYPE'] = '[1]' app.config['CACHE_DEFAULT_TIMEOUT'] = [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'redis' without having Redis installed or configured.
Setting timeout to 60 instead of 300.
✗ Incorrect
Use 'simple' for basic in-memory caching and set timeout to 300 seconds.
5fill in blank
hardFill all three blanks to create a cached route that returns JSON with a 120 seconds cache timeout.
Flask
@app.route('/data') @cache.[1](timeout=[2]) def data(): return [3]({'message': 'Hello, world!'})
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong decorator name like 'cache_response'.
Returning a dict directly instead of using jsonify.
Setting timeout to wrong values.
✗ Incorrect
The route uses the cached decorator with timeout 120 seconds and returns JSON using jsonify.