Settings

class requests_cache.policy.settings.CacheSettings(allowable_codes=(200,), allowable_methods=('GET', 'HEAD'), always_revalidate=False, autoclose=True, cache_control=False, content_root_key=None, disabled=False, expire_after=None, filter_fn=None, ignored_parameters=('Authorization', 'Proxy-Authorization', 'X-API-Key', 'X-Auth-Token', 'X-API-Token', 'X-Access-Token', 'access_token', 'api_key', 'apikey'), key_fn=None, match_headers=False, only_if_cached=False, read_only=False, stale_if_error=False, stale_while_revalidate=False, urls_expire_after=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
autoclose: bool
cache_control: bool
content_root_key: Optional[str]
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
read_only: 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]]