<PackageReference Include="Azure.Storage.Common" Version="12.30.0-beta.1" />

Azure.Storage.AutoRefreshingCache<TValue>

sealed class AutoRefreshingCache<TValue> where TValue : struct, IExpiringValue, IEquatable<TValue>
A thread-safe cache for a single expiring value that supports automatic proactive background refresh. Only one acquisition runs at a time; concurrent callers wait on the same TaskCompletionSource<T> rather than issuing duplicate acquire calls.

Modeled after BearerTokenAuthenticationPolicy.AccessTokenCache in Azure.Core but fully generic.

public sealed delegate AcquireDelegate<TValue> : MulticastDelegate where TValue : struct, IExpiringValue, IEquatable<TValue>

Delegate the cache calls to acquire or refresh the value.

public AutoRefreshingCache(AcquireDelegate<TValue> acquire, TimeSpan backgroundAcquireTimeout)

public ValueTask<TValue> GetAsync(bool async, CancellationToken cancellationToken)

Returns the cached value, acquiring or refreshing it as necessary. The first caller triggers acquisition; concurrent callers wait on the same result. When the value approaches expiry, a background refresh is initiated so that no caller blocks on a stale value. Note: this method may throw exceptions from the acquire delegate. It also assumes that the acquired value will be valid upon retrieval.

public void InvalidateIfCurrent(TValue expectedValue)

Clears the cached value only if the currently cached value equals expectedValue. The next call to GetAsync after a successful invalidation will trigger a fresh acquisition.