class documentation
class RenewableFileCacheReceiver(ParentReceiver): (source)
Constructor: RenewableFileCacheReceiver(bearer, cache)
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 | |
| bearer | The parent RenewableFileCacheBearer containing
configuration such as safety_margin and the wrapped bearer instance. |
| cache | The throttled file-backed token cache. |
| bearer | The owning renewable bearer. |
| cache | The throttled token cache used for storage. |
| Method | __init__ |
Create a renewable receiver. |
| Method | can |
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 |
Undocumented |
| Instance Variable | _last |
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. |
Create a renewable receiver.
No file I/O occurs during construction; the cache performs lazy I/O when accessed.
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:Exception | The exception that occurred. |
options:dict[ | Optional receiver options forwarded to the wrapped receiver when applicable. |
| Returns | |
bool | Whether the operation should be retried. |