Cache Keys#
Internal utilities for generating cache keys that are used for request matching
Create a normalized cache key based on a request object  | 
|
Normalize and filter a request body if possible, depending on Content-Type  | 
|
Sort and filter request headers, and normalize minor variations in multi-value headers  | 
|
Normalize and remove ignored parameters from request URL, body, and headers.  | 
|
Normalize and filter urlencoded params from either a URL or request body with form data  | 
|
Normalize and filter a URL.  | 
- requests_cache.cache_keys.create_key(request, ignored_parameters=None, match_headers=False, serializer=None, **request_kwargs)[source]#
 Create a normalized cache key based on a request object
- Parameters:
 request (
Union[Request,PreparedRequest,CachedRequest]) – Request object to generate a cache key fromignored_parameters (
Optional[Iterable[str]]) – Request paramters, headers, and/or JSON body params to excludematch_headers (
Union[Iterable[str],None,bool]) – Match only the specified headers, orTrueto match all headersrequest_kwargs – Additional keyword arguments for
request()
- Return type:
 
- requests_cache.cache_keys.get_matched_headers(headers, match_headers)[source]#
 Get only the headers we should match against as a list of
k=vstrings, given an optional include list.
- requests_cache.cache_keys.normalize_body(request, ignored_parameters)[source]#
 Normalize and filter a request body if possible, depending on Content-Type
- Parameters:
 request (
Union[PreparedRequest,CachedRequest]) –
- Return type:
 
- requests_cache.cache_keys.normalize_headers(headers, ignored_parameters=None)[source]#
 Sort and filter request headers, and normalize minor variations in multi-value headers
- requests_cache.cache_keys.normalize_json_body(original_body, ignored_parameters)[source]#
 Normalize and filter a request body with serialized JSON data
- requests_cache.cache_keys.normalize_params(value, ignored_parameters=None)[source]#
 Normalize and filter urlencoded params from either a URL or request body with form data
- requests_cache.cache_keys.normalize_request(request, ignored_parameters=None)[source]#
 Normalize and remove ignored parameters from request URL, body, and headers. This is used for both:
Increasing cache hits by generating more precise cache keys
Redacting potentially sensitive info from cached requests
- Parameters:
 request (
Union[Request,PreparedRequest,CachedRequest]) – Request object to normalizeignored_parameters (
Optional[Iterable[str]]) – Request paramters, headers, and/or JSON body params to exclude
- Return type:
 
- requests_cache.cache_keys.normalize_url(url, ignored_parameters)[source]#
 Normalize and filter a URL. This includes request parameters, IDN domains, scheme, host, port, etc.
- requests_cache.cache_keys.redact_response(response, ignored_parameters)[source]#
 Redact any ignored parameters (potentially containing sensitive info) from a cached request
- Parameters:
 response (
CachedResponse) –
- Return type: