0
0
Flaskframework~10 mins

Flask-Caching for response caching - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ACacheManager
BCache
CCacheControl
DCacheExtension
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'CacheControl' which is unrelated to Flask-Caching.
Using 'CacheManager' which does not exist in this package.
2fill in blank
medium

Complete the code to initialize caching with Flask app.

Flask
cache = [1](app)
Drag options to blanks, or click blank then click option'
ACache
BCacheControl
CCacheManager
DCacheExtension
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong class name like 'CacheControl'.
Forgetting to pass the app instance.
3fill in blank
hard

Fix 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'
Acache_response
Bcache_response_for
Ccache_it
Dcached
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent decorator names like 'cache_response'.
Confusing with other caching libraries.
4fill in blank
hard

Fill 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'
Asimple
Bredis
C300
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'redis' without having Redis installed or configured.
Setting timeout to 60 instead of 300.
5fill in blank
hard

Fill 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'
Acached
B120
Cjsonify
Dcache_response
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.