Table of Contents

Interface IKeyCache

Namespace
Excalibur.Compliance
Assembly
Excalibur.Compliance.Abstractions.dll

Provides caching for encryption key metadata with configurable TTL.

public interface IKeyCache
Extension Methods

Remarks

Caching key metadata (not key material) reduces latency and KMS API calls. Implementations should:

  • Never cache actual key material
  • Use sliding or absolute expiration based on configuration
  • Support cache invalidation on key rotation
  • Report cache hits/misses via telemetry

Properties

Count

Gets the current number of cached entries.

int Count { get; }

Property Value

int

Methods

GetOrAddAsync(string, Func<string, CancellationToken, Task<KeyMetadata?>>, CancellationToken)

Retrieves key metadata from the cache, or fetches and caches it if not present.

Task<KeyMetadata?> GetOrAddAsync(string keyId, Func<string, CancellationToken, Task<KeyMetadata?>> factory, CancellationToken cancellationToken)

Parameters

keyId string

The key identifier.

factory Func<string, CancellationToken, Task<KeyMetadata>>

A factory function to retrieve the key if not in cache.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<KeyMetadata>

The key metadata, or null if the key does not exist.

Remove(string)

Removes key metadata from the cache.

void Remove(string keyId)

Parameters

keyId string

The key identifier to remove.

Set(KeyMetadata)

Adds or updates key metadata in the cache.

void Set(KeyMetadata keyMetadata)

Parameters

keyMetadata KeyMetadata

The key metadata to cache.

TryGet(string)

Attempts to retrieve key metadata from the cache.

KeyMetadata? TryGet(string keyId)

Parameters

keyId string

The key identifier.

Returns

KeyMetadata

The cached key metadata, or null if not in cache.