class ThrottledTokenCache: (source)
Constructor: ThrottledTokenCache(name, cache_file, throttle)
A throttled file-based token cache.
The helper keeps an in-memory cached token for throttle seconds
to avoid repeated reads from the underlying TokenCache.
| Parameters | |
| name | The key name under which the token is stored in the
underlying TokenCache. |
| cache | Path to the underlying YAML cache file. |
| throttle | Duration (timedelta or seconds as float) to hold the in-memory cached token. If a float is supplied it is interpreted as seconds. |
| Method | __init__ |
Create a throttled token cache. |
| Async Method | get |
Return the cached token, refreshing from disk if throttling allows. |
| Method | get |
Return the in-memory cached token without consulting disk. |
| Async Method | refresh |
Refresh the in-memory token from the underlying cache. |
| Async Method | remove |
Remove the token from both the underlying cache and the in-memory cache. |
| Async Method | remove |
Remove the token if it equals the provided token. |
| Async Method | set |
Store the token in the underlying cache and update the in-memory cache and throttle expiration. |
| Instance Variable | _cache |
Undocumented |
| Instance Variable | _cached |
Undocumented |
| Instance Variable | _name |
Undocumented |
| Instance Variable | _next |
Undocumented |
| Instance Variable | _throttle |
Undocumented |
str, cache_file: str | Path = Path(timedelta | float = timedelta(Create a throttled token cache.
Return the cached token, refreshing from disk if throttling allows.
If the in-memory token is present, not expired and the throttle
period has not elapsed the cached token is returned. Otherwise
the underlying TokenCache.get is called.
| Returns | |
Token | None | The cached Token or None if no valid token is found. |
Refresh the in-memory token from the underlying cache.
If the token exists on disk and is not expired the in-memory cache and throttle are updated and the token is returned.
Remove the token if it equals the provided token.
This performs an atomic check-and-remove against the underlying cache and updates the in-memory state when the removal occurs.