src.ska_src_api_accounting.cache.redis
Redis-backed implementation of a token cache for OAuth2 service tokens.
Module Contents
Classes
A Redis-based cache implementation for storing and retrieving OAuth2 tokens. |
- class src.ska_src_api_accounting.cache.redis.RedisCache(host, port, logger=None)
Bases:
ska_src_api_accounting.cache.cache.CacheA Redis-based cache implementation for storing and retrieving OAuth2 tokens.
This class stores tokens in Redis using a key derived from the token’s scopes and audiences. Tokens are serialised to JSON and automatically validated for expiration before being returned. Expired tokens are removed from the cache.
Optionally, a key prefix can be used to namespace cached entries. Keys are deterministically generated by alphabetically sorting scopes and audiences.
- __get_key(audiences, key_prefix, scopes)
- get_cache_token(scopes, audiences, key_prefix=None)
Retrieve a cached token from Redis using scopes and audiences as the cache key.
The cache key is generated by alphabetically sorting the scopes and audiences, and optionally prepending a key prefix for namespacing.
- set_cache_token(scopes, audiences, token, key_prefix=None)
Store a token in Redis with a key based on scopes and audiences.
The cache key is generated by alphabetically sorting the scopes and audiences, and optionally prepending a key prefix for namespacing. The token is serialized to JSON before being stored.