Class NullKeyCache
- Namespace
- Excalibur.Compliance.Encryption
- Assembly
- Excalibur.Compliance.dll
A no-op implementation of IKeyCache following the Null Object pattern.
public sealed class NullKeyCache : IKeyCache
- Inheritance
-
NullKeyCache
- Implements
- Inherited Members
- Extension Methods
Remarks
This class implements the Null Object design pattern: it fulfills the IKeyCache contract but performs no actual caching. Every call to GetOrAddAsync(string, Func<string, CancellationToken, Task<KeyMetadata?>>, CancellationToken) delegates directly to the factory, and all mutation methods (Set(KeyMetadata), Remove(string), Clear()) are intentional no-ops.
Use this implementation when:
- Encryption key caching is explicitly disabled via configuration.
- A test double is needed that guarantees no caching side effects.
- A non-null IKeyCache is required by a constructor but caching is unwanted.
Properties
Count
Gets the current number of cached entries.
public int Count { get; }
Property Value
Instance
Gets the singleton instance of NullKeyCache.
public static NullKeyCache Instance { get; }
Property Value
Methods
Clear()
No-op clear for cache bypass scenarios.
public void Clear()
GetOrAddAsync(string, Func<string, CancellationToken, Task<KeyMetadata?>>, CancellationToken)
Retrieves key metadata from the cache, or fetches and caches it if not present.
public 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.
GetOrAddAsync(string, TimeSpan, Func<string, CancellationToken, Task<KeyMetadata?>>, CancellationToken)
No-op get-or-add with TTL for cache bypass scenarios. Always calls the factory since nothing is cached.
public Task<KeyMetadata?> GetOrAddAsync(string keyId, TimeSpan ttl, Func<string, CancellationToken, Task<KeyMetadata?>> factory, CancellationToken cancellationToken)
Parameters
keyIdstringThe key identifier.
ttlTimeSpanThe time-to-live (ignored).
factoryFunc<string, CancellationToken, Task<KeyMetadata>>The factory function to retrieve the key.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<KeyMetadata>
The result from the factory.
Invalidate(string)
No-op invalidation for cache bypass scenarios.
public void Invalidate(string keyId)
Parameters
keyIdstringThe key identifier (ignored).
Remove(string)
Removes key metadata from the cache.
public void Remove(string keyId)
Parameters
keyIdstringThe key identifier to remove.
Set(KeyMetadata)
Adds or updates key metadata in the cache.
public void Set(KeyMetadata keyMetadata)
Parameters
keyMetadataKeyMetadataThe key metadata to cache.
Set(KeyMetadata, TimeSpan)
No-op set with TTL for cache bypass scenarios.
public void Set(KeyMetadata keyMetadata, TimeSpan ttl)
Parameters
keyMetadataKeyMetadataThe key metadata (ignored).
ttlTimeSpanThe time-to-live (ignored).
TryGet(string)
Attempts to retrieve key metadata from the cache.
public KeyMetadata? TryGet(string keyId)
Parameters
keyIdstringThe key identifier.
Returns
- KeyMetadata
The cached key metadata, or null if not in cache.