/// <inheritdoc /> public void AddExpiration(ExpiryToken <TKey> expiration) { IExpiryStashContracts.AddExpiration(this); while (!this.tokens.TryAdd(expiration)) { ExpiryToken <TKey> overflow; if (this.tokens.TryTake(out overflow)) { overflow.TryDisposeCacheValue(); } } }
/// <inheritdoc /> public void AddExpiration(ExpiryToken <TKey> expiration) { IExpiryStashContracts.AddExpiration(this); if (this.awaitingTokensCount.Read() <= 0) { // not awaiting a token so store it for disposal later this.stash.AddExpiration(expiration); } else { // pool is empty and Take/TakeAsync is awaiting a value so dispose token immediately expiration.TryDisposeCacheValue(); } }
/// <inheritdoc /> public bool TryDisposeAndRemove(ExpiryToken <TKey> expirationToken) { if (this.IsTokenExpired(expirationToken)) { return(false); } if (this.TryDispose()) { this.cache.entries.TryRemove(this.Key); return(true); } else { return(false); } }
/// <inheritdoc /> public void AddExpiration(ExpiryToken <TKey> expiration) { ICacheValueContracts.AddExpiration(this); this.stash.AddExpiration(expiration); }
/// <inheritdoc /> public void AddExpiration(ExpiryToken <TKey> expiration) { ICacheValueContracts.AddExpiration(this); expiration.TryDisposeCacheValue(); }
/// <inheritdoc /> public bool IsTokenExpired(ExpiryToken <TKey> expirationToken) => expirationToken.TokenVersion != this.tokenVersion.Read();