class documentation

Receiver that returns a cached token when safe, or refreshes it.

The receiver first consults the provided ThrottledTokenCache. If the cached token is missing or too close to expiration (depending on the parent's safety_margin), the receiver will fetch a fresh token from the wrapped bearer and persist it to the cache.

Behavior

  • When the cache holds a non-expired token and it is outside the safety margin, that token is returned immediately.
  • Otherwise a receiver from the wrapped bearer is used to fetch a fresh token. The new token is saved to the cache on success.
Parameters
bearerThe parent RenewableFileCacheBearer containing configuration such as safety_margin and the wrapped bearer instance.
cacheThe throttled file-backed token cache.
bearerThe owning renewable bearer.
cacheThe throttled token cache used for storage.
Method __init__ Create a renewable receiver.
Method can_retry Decide whether an error should be retried.
Async Method _fetch Return a cached token when valid or fetch and store a new one.
Instance Variable _bearer Undocumented
Instance Variable _cache Undocumented
Instance Variable _from_cache Undocumented
Instance Variable _last_saved Undocumented
Instance Variable _receiver Undocumented

Inherited from Receiver:

Async Method fetch Fetch a token and record it as the latest value.
Property latest Return the latest fetched token or None.
Instance Variable _latest The most recently fetched token, or None if no token has been fetched yet. Implementations may update this to support inspection or caching by callers.
def __init__(self, bearer: RenewableFileCacheBearer, cache: ThrottledTokenCache): (source)

Create a renewable receiver.

No file I/O occurs during construction; the cache performs lazy I/O when accessed.

def can_retry(self, err: Exception, options: dict[str, str] | None = None) -> bool: (source)

Decide whether an error should be retried.

  • If the previous attempt read from cache, allow one retry so callers can fall back to the wrapped receiver.
  • If no wrapped receiver exists yet, permit retry so the first fetch attempt can create it.
  • Otherwise defer to the wrapped receiver's can_retry.
Parameters
err:ExceptionThe exception that occurred.
options:dict[str, str] | NoneOptional receiver options forwarded to the wrapped receiver when applicable.
Returns
boolWhether the operation should be retried.
async def _fetch(self, timeout: float | None = None, options: dict[str, str] | None = None) -> Token: (source)

Return a cached token when valid or fetch and store a new one.

Parameters
timeout:float | NonePass-through timeout to the wrapped receiver.
options:dict[str, str] | NoneOptional fetch options forwarded to the wrapped receiver.
Returns
TokenA valid Token (possibly empty).

Undocumented

Undocumented

_from_cache: bool = (source)

Undocumented

_last_saved: Token | None = (source)

Undocumented

Undocumented