(request, response, secs=0, force=False)
Tool for influencing cache mechanisms using the 'Expires' header.

    'secs' must be either an int or a datetime.timedelta, and indicates the
    number of seconds between response.time and when the response should
    expire. The 'Expires' header will be set to (response.time + secs).

    If 'secs' is zero, the 'Expires' header is set one year in the past, and
    the following "cache prevention" headers are also set:
    - 'Pragma': 'no-cache'
    - 'Cache-Control': 'no-cache, must-revalidate'

    If 'force' is False (the default), the following headers are checked:
    'Etag', 'Last-Modified', 'Age', 'Expires'. If any are already present,
    none of the above response headers are set.
Tool for influencing cache mechanisms using the 'Expires' header.
Tool for influencing cache mechanisms using the Expires header .
def expires(request, response, secs=0, force=False):
    """Tool for influencing cache mechanisms using the 'Expires' header.

    'secs' must be either an int or a datetime.timedelta, and indicates the
    number of seconds between response.time and when the response should
    expire. The 'Expires' header will be set to (response.time + secs).

    If 'secs' is zero, the 'Expires' header is set one year in the past, and
    the following "cache prevention" headers are also set:
    - 'Pragma': 'no-cache'
    - 'Cache-Control': 'no-cache, must-revalidate'

    If 'force' is False (the default), the following headers are checked:
    'Etag', 'Last-Modified', 'Age', 'Expires'. If any are already present,
    none of the above response headers are set.
    """

    headers = response.headers

    cacheable = False
    if not force:
        # some header names that indicate that the response can be cached
        for indicator in ('Etag', 'Last-Modified', 'Age', 'Expires'):
            if indicator in headers:
                cacheable = True
                break

    if not cacheable:
        if isinstance(secs, timedelta):
            secs = (86400 * secs.days) + secs.seconds

        if secs == 0:
            if force or "Pragma" not in headers:
                headers["Pragma"] = "no-cache"
            if request.protocol >= (1, 1):
                if force or "Cache-Control" not in headers:
                    headers["Cache-Control"] = "no-cache, must-revalidate"
            # Set an explicit Expires date in the past.
            now = datetime.now()
            lastyear = now.replace(year=now.year - 1)
            expiry = formatdate(
                mktime(lastyear.timetuple()), usegmt=True
            )
        else:
            expiry = formatdate(response.time + secs, usegmt=True)
        if force or "Expires" not in headers:
            headers["Expires"] = expiry
def expires ( request , response , secs = 0 , force = False ) : headers = response . headers cacheable = False if not force : # some header names that indicate that the response can be cached for indicator in ( 'Etag' , 'Last-Modified' , 'Age' , 'Expires' ) : if indicator in headers : cacheable = True break if not cacheable : if isinstance ( secs , timedelta ) : secs = ( 86400 * secs . days ) + secs . seconds if secs == 0 : if force or "Pragma" not in headers : headers [ "Pragma" ] = "no-cache" if request . protocol >= ( 1 , 1 ) : if force or "Cache-Control" not in headers : headers [ "Cache-Control" ] = "no-cache, must-revalidate" # Set an explicit Expires date in the past. now = datetime . now ( ) lastyear = now . replace ( year = now . year - 1 ) expiry = formatdate ( mktime ( lastyear . timetuple ( ) ) , usegmt = True ) else : expiry = formatdate ( response . time + secs , usegmt = True ) if force or "Expires" not in headers : headers [ "Expires" ] = expiry