Directives#

class requests_cache.policy.directives.CacheDirectives(expires=None, immutable=False, max_age=None, max_stale=None, min_fresh=None, must_revalidate=False, no_cache=False, no_store=False, only_if_cached=False, stale_if_error=None, stale_while_revalidate=None, etag=None, last_modified=None)[source]#

Bases: RichMixin

Parses Cache-Control directives and other relevant cache settings from either request or response headers

Parameters:
etag: str#
expires: str#
classmethod from_headers(headers)[source]#

Parse cache directives and other settings from request or response headers

Parameters:

headers (MutableMapping[str, str]) –

get_expire_offset()[source]#

Return the time offset to use for expiration, if either min-fresh or max-stale is set

Return type:

timedelta

property has_validator: bool#
immutable: bool#
last_modified: str#
max_age: int#
max_stale: int#
min_fresh: int#
must_revalidate: bool#
no_cache: bool#
no_store: bool#
only_if_cached: bool#
stale_if_error: int#
stale_while_revalidate: int#
requests_cache.policy.directives.set_request_headers(headers, expire_after, only_if_cached, refresh, force_refresh)[source]#

Translate keyword arguments into equivalent request headers

Parameters:

headers (Optional[MutableMapping[str, str]]) –