Table of Contents

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

int

Instance

Gets the singleton instance of NullKeyCache.

public static NullKeyCache Instance { get; }

Property Value

NullKeyCache

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

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.

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

keyId string

The key identifier.

ttl TimeSpan

The time-to-live (ignored).

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

The factory function to retrieve the key.

cancellationToken CancellationToken

A 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

keyId string

The key identifier (ignored).

Remove(string)

Removes key metadata from the cache.

public void Remove(string keyId)

Parameters

keyId string

The key identifier to remove.

Set(KeyMetadata)

Adds or updates key metadata in the cache.

public void Set(KeyMetadata keyMetadata)

Parameters

keyMetadata KeyMetadata

The key metadata to cache.

Set(KeyMetadata, TimeSpan)

No-op set with TTL for cache bypass scenarios.

public void Set(KeyMetadata keyMetadata, TimeSpan ttl)

Parameters

keyMetadata KeyMetadata

The key metadata (ignored).

ttl TimeSpan

The time-to-live (ignored).

TryGet(string)

Attempts to retrieve key metadata from the cache.

public KeyMetadata? TryGet(string keyId)

Parameters

keyId string

The key identifier.

Returns

KeyMetadata

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