Skip to content

Conversation

@tobyhede
Copy link
Contributor

@tobyhede tobyhede commented Aug 20, 2025

The client scoped_cipher fetches keyset information on init.
In multitenant operation, many keysets are used, and the initialisation occurs on every encrypt or decrypt operation.
Once initialised, scoped_ciphers should be retained to avoid the cost of the initial request for every operation.

Implements an in-memory cache for ScopedCipher instances to improve performance by avoiding repeated ZeroKMS cipher initialization. Key features:

  • Configurable cache size (CS_SERVER__CIPHER_CACHE_SIZE, default: 64 entries)
  • Configurable TTL (CS_SERVER__CIPHER_CACHE_TTL_SECONDS, default: 3600s)
  • Memory-aware caching with estimated 3KB per cipher entry
  • Prometheus metrics for cache hits and cipher initialization tracking
  • Keyset-scoped caching with proper cache key generation

Implements an in-memory cache for ScopedCipher instances to improve performance by avoiding repeated ZeroKMS cipher initialization. Key features:

- Configurable cache size (CS_SERVER__CIPHER_CACHE_SIZE, default: 64 entries)
- Configurable TTL (CS_SERVER__CIPHER_CACHE_TTL_SECONDS, default: 3600s)
- Memory-aware caching with estimated 3KB per cipher entry
- Prometheus metrics for cache hits and cipher initialization tracking
- Keyset-scoped caching with proper cache key generation
@tobyhede tobyhede changed the title feat: cache initialised scoped_cipher/s feat: ✨ add configurable cipher caching with async Moka Aug 21, 2025
Copy link
Contributor

@freshtonic freshtonic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but see my comment about using std::mem::size_of

@tobyhede tobyhede merged commit df1dab7 into main Aug 21, 2025
2 checks passed
@tobyhede tobyhede deleted the scoped-cipher-lru branch August 21, 2025 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants