Bird
0
0

Given this Flask code snippet using Flask-Caching, what will be printed on the second request to /time within 10 seconds?

medium📝 component behavior Q13 of 15
Flask - Middleware and Extensions
Given this Flask code snippet using Flask-Caching, what will be printed on the second request to /time within 10 seconds?
from flask import Flask
from flask_caching import Cache
import time

app = Flask(__name__)
cache = Cache(app, config={'CACHE_TYPE': 'simple'})

@app.route('/time')
@cache.cached(timeout=10)
def get_time():
    return str(time.time())

# Assume the first request prints 1680000000.0
AA new timestamp different from 1680000000.0
BThe string 'None'
CAn error because caching is not configured
DThe same timestamp 1680000000.0
Step-by-Step Solution
Solution:
  1. Step 1: Understand caching behavior

    The first call caches the response (timestamp) for 10 seconds.
  2. Step 2: Predict second request output within timeout

    Within 10 seconds, the cached response is returned, so the timestamp stays the same.
  3. Final Answer:

    The same timestamp 1680000000.0 -> Option D
  4. Quick Check:

    Cached response repeats within timeout = D [OK]
Quick Trick: Cached output repeats until timeout expires [OK]
Common Mistakes:
MISTAKES
  • Expecting a new timestamp every request
  • Assuming caching is disabled without error
  • Confusing cache timeout with immediate refresh

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes