Class PartitionedShield<TKey, TResult>
- Namespace
- Kevlar
- Assembly
- Kevlar.dll
Selects and retains an independent result-aware Shield<TResult> for each partition key.
public sealed class PartitionedShield<TKey, TResult> : IDisposable, IAsyncDisposable where TKey : notnull
Type Parameters
TKeyTResult
- Inheritance
-
PartitionedShield<TKey, TResult>
- Implements
- Inherited Members
Remarks
Retention is bounded by MaxPartitions. After the eviction callback and active executions complete, disposable strategies owned by an evicted shield are released. Shared strategy instances are disposed after their last partition owner. By default the provider owns every strategy returned by its factory; set OwnsStrategies to false when those instances are also used outside the provider. Do not reuse a shield after its partition is evicted. A later lookup creates a fresh partition with fresh strategy state. Partition keys are never added to metric tags or shield names automatically.
Constructors
PartitionedShield(Func<TKey, Shield<TResult>>, PartitionedShieldOptions<TKey, TResult>?, IEqualityComparer<TKey>?)
Creates a bounded result-aware partition provider.
public PartitionedShield(Func<TKey, Shield<TResult>> factory, PartitionedShieldOptions<TKey, TResult>? options = null, IEqualityComparer<TKey>? comparer = null)
Parameters
factoryFunc<TKey, Shield<TResult>>optionsPartitionedShieldOptions<TKey, TResult>comparerIEqualityComparer<TKey>
Properties
CapacityEvictionCount
Gets the total number evicted to enforce the capacity bound.
public long CapacityEvictionCount { get; }
Property Value
ClearedEvictionCount
Gets the total number removed explicitly through remove or clear operations.
public long ClearedEvictionCount { get; }
Property Value
Count
Gets the current number of retained partitions.
public int Count { get; }
Property Value
CreatedCount
Gets the total number of partitions created by this provider.
public long CreatedCount { get; }
Property Value
EvictionCount
Gets the total number of partitions removed for any reason.
public long EvictionCount { get; }
Property Value
ExpirationEvictionCount
Gets the total number evicted after their idle expiration elapsed.
public long ExpirationEvictionCount { get; }
Property Value
Methods
Clear()
Removes every retained partition and begins configured lifecycle cleanup.
public void Clear()
ClearAsync()
Asynchronously removes every retained partition.
public ValueTask ClearAsync()
Returns
CreateAsync(Func<TKey, ValueTask<Shield<TResult>>>, PartitionedShieldOptions<TKey, TResult>?, IEqualityComparer<TKey>?)
Creates a bounded result-aware partition provider with an asynchronous factory.
public static PartitionedShield<TKey, TResult> CreateAsync(Func<TKey, ValueTask<Shield<TResult>>> factory, PartitionedShieldOptions<TKey, TResult>? options = null, IEqualityComparer<TKey>? comparer = null)
Parameters
factoryFunc<TKey, ValueTask<Shield<TResult>>>optionsPartitionedShieldOptions<TKey, TResult>comparerIEqualityComparer<TKey>
Returns
- PartitionedShield<TKey, TResult>
Dispose()
Disposes strategies owned by every retained partition.
public void Dispose()
DisposeAsync()
Asynchronously waits for in-flight factories, removals, and executions, then disposes strategies owned by every retained partition. Concurrent callers await the same disposal operation.
public ValueTask DisposeAsync()
Returns
GetShield(TKey)
Gets or creates the result-aware shield for key.
public Shield<TResult> GetShield(TKey key)
Parameters
keyTKey
Returns
- Shield<TResult>
GetShieldAsync(TKey)
Asynchronously gets or creates the result-aware shield for key.
public ValueTask<Shield<TResult>> GetShieldAsync(TKey key)
Parameters
keyTKey
Returns
PruneExpired()
Removes partitions whose configured idle expiration has elapsed.
public int PruneExpired()
Returns
- int
The number removed.
PruneExpiredAsync()
Asynchronously removes partitions whose idle expiration has elapsed.
public ValueTask<int> PruneExpiredAsync()
Returns
TryGetShield(TKey, out Shield<TResult>?)
Gets a retained result-aware shield without creating one.
public bool TryGetShield(TKey key, out Shield<TResult>? shield)
Parameters
keyTKeyshieldShield<TResult>
Returns
TryRemove(TKey)
Removes a retained partition and begins its configured lifecycle cleanup.
public bool TryRemove(TKey key)
Parameters
keyTKey
Returns
TryRemoveAsync(TKey)
Asynchronously removes a retained partition.
public ValueTask<bool> TryRemoveAsync(TKey key)
Parameters
keyTKey