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
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
keyIdstringThe key identifier.
factoryFunc<string, CancellationToken, Task<KeyMetadata>>A factory function to retrieve the key if not in cache.
cancellationTokenCancellationTokenA 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
keyIdstringThe key identifier to remove.
Set(KeyMetadata)
Adds or updates key metadata in the cache.
void Set(KeyMetadata keyMetadata)
Parameters
keyMetadataKeyMetadataThe key metadata to cache.
TryGet(string)
Attempts to retrieve key metadata from the cache.
KeyMetadata? TryGet(string keyId)
Parameters
keyIdstringThe key identifier.
Returns
- KeyMetadata
The cached key metadata, or null if not in cache.