Settings#

class requests_cache.policy.settings.CacheSettings(allowable_codes=(200,), allowable_methods=('GET', 'HEAD'), always_revalidate=False, cache_control=False, disabled=False, expire_after=None, filter_fn=None, ignored_parameters=('Authorization', 'X-API-KEY', 'access_token', 'api_key'), key_fn=None, match_headers=False, only_if_cached=False, stale_if_error=False, stale_while_revalidate=False, urls_expire_after=_Nothing.NOTHING)[source]#

Bases: RichMixin

Class used internally to store settings that affect caching behavior. This allows settings to be used across multiple modules, but exposed to the user in a single property (CachedSession.settings). These values can safely be modified after initialization. See CachedSession and User Guide for usage details.

Parameters:
allowable_codes: Iterable[int]#
allowable_methods: Iterable[str]#
always_revalidate: bool#
cache_control: bool#
disabled: bool#
expire_after: Union[None, int, float, str, datetime, timedelta]#
filter_fn: Callable[[Response], bool]#
classmethod from_kwargs(**kwargs)[source]#

Constructor with some additional steps:

  • Handle some deprecated argument names

  • Ignore invalid settings, for easier initialization from mixed **kwargs

ignored_parameters: Iterable[str]#
key_fn: Callable[..., str]#
match_headers: Union[Iterable[str], bool]#
only_if_cached: bool#
stale_if_error: Union[bool, None, int, float, str, datetime, timedelta]#
stale_while_revalidate: Union[bool, None, int, float, str, datetime, timedelta]#
urls_expire_after: Dict[Union[str, Pattern], Union[None, int, float, str, datetime, timedelta]]#