Skip to main content
RefreshableCacheRegistry is a standalone refreshable cache for secrets or any fetched values, usable in any Python project with no Bakebook required. Subclass FetchFn to declare how a value is fetched, register it under a key, and the first get fetches and caches it:

Refreshing rotated secrets

For secrets rotated while your process runs, wrap the call in @cache.catch_refresh and raise RefreshNeededError when the service rejects the cached value:
The cache then clears and call_api retries, re-fetching a fresh token via cache.get(). Retries are tenacity-backed (stop/wait, defaults 2 attempts, no delay), so secrets refresh at runtime with no restart. acatch_refresh is the async variant.

Backends

  • MemoryCache - default, ephemeral
  • KeyringCache - system keyring, persistent
  • ChainedCache - several backends, read-first/write-all
  • NullCache - disabled
A single backend is used directly, multiple are wrapped in ChainedCache. Pass ttl= for expiry. Secrets wires this registry into a Bakebook with bake secret commands.