expiration

Summary

get_expiration(response[, …])

Get the appropriate expiration for the given response, in order of precedence: 1.

get_expiration_datetime(expire_after)

Convert a relative time value or delta to an absolute datetime, if it’s not already

get_expiration_for_url(url[, urls_expire_after])

Check for a matching per-URL expiration, if any

url_match(url, pattern)

Determine if a URL matches a pattern

Module Contents

Functions for determining cache expiration

get_expiration(response, request_expire_after=None, session_expire_after=None, urls_expire_after=None)

Get the appropriate expiration for the given response, in order of precedence: 1. Per-request expiration 2. Per-URL expiration 3. Per-session expiration

Return type

Optional[datetime]

Returns

An absolute expiration datetime or None

Parameters
get_expiration_datetime(expire_after)

Convert a relative time value or delta to an absolute datetime, if it’s not already

Return type

Optional[datetime]

Parameters

expire_after (Union[None, int, float, datetime.datetime, datetime.timedelta]) –

get_expiration_for_url(url, urls_expire_after=None)

Check for a matching per-URL expiration, if any

Return type

Union[None, int, float, datetime, timedelta]

Parameters
url_match(url, pattern)

Determine if a URL matches a pattern

Parameters
  • url (Union[str, URL]) – URL to test. Its base URL (without protocol) will be used.

  • pattern (str) – Glob pattern to match against. A recursive wildcard will be added if not present

Return type

bool

Example

>>> url_match('https://httpbin.org/delay/1', 'httpbin.org/delay')
True
>>> url_match('https://httpbin.org/stream/1', 'httpbin.org/*/1')
True
>>> url_match('https://httpbin.org/stream/2', 'httpbin.org/*/1')
False
Return type

bool

Parameters
  • url (Union[str, yarl.URL]) –

  • pattern (str) –