- class requests_cache.policy.actions.CacheActions(cache_key=None, error_504=False, expire_after=None, send_request=False, resend_request=False, resend_async=False, skip_read=False, skip_write=False, directives=None, settings=None, only_if_cached=False, refresh=False, request=None, stale_if_error=None, stale_while_revalidate=None, validation_headers=_Nothing.NOTHING)[source]#
- Translates cache settings and headers into specific actions to take for a given cache item.
The resulting actions are then handled in
See Expiration Precedence for behavior if multiple sources provide an expiration
See Cache Headers for more details about header behavior
The following arguments/properties are the outputs of this class:
str]) – The cache key created based on the initial request
bool) – Indicates the request cannot be fulfilled based on cache settings
timedelta]) – User or header-provided expiration value
bool) – Send a new request
bool) – Send a new request to refresh a stale cache item
bool) – Return a stale cache item, and send a non-blocking request to refresh it
bool) – Skip reading from the cache
bool) – Skip writing to the cache
- property expires: Optional[datetime]#
Convert the user/header-provided expiration value to a datetime. Applies to new cached responses, and previously cached responses that are being revalidated.
- classmethod from_request(cache_key, request, settings=None)[source]#
Initialize from request info and cache settings.
Note on refreshing: must-revalidate isn’t a standard request header, but is used here to indicate a user-requested refresh. Typically that’s only used in response headers, and max-age=0 would be used by a client to request a refresh. However, this would conflict with the expire_after option provided in
PreparedRequest) – The outgoing request
CacheSettings]) – Session-level cache settings
- is_usable(cached_response, error=False)[source]#
Determine whether a given cached response is “fresh enough” to satisfy the request, based on:
stale-if-error (if an error has occured)
- update_from_cached_response(cached_response, create_key=None, **key_kwargs)[source]#
Determine if we can reuse a cached response, or set headers for a conditional request if possible.
Used after fetching a cached response, but before potentially sending a new request.
Update expiration + actions based on headers and other details from a new response.
Used after receiving a new response, but before saving it to the cache.
Apply validation headers (if any) before sending a request
- Return type:
- update_revalidated_response(response, cached_response)[source]#
After revalidation, update the cached response’s expiration and headers
cached_response (CachedResponse) –
- Return type: