/// <summary> /// Put a Safe Cache Entry Asynchronously. /// </summary> /// <param name="safeCacheEntry"> /// A <see cref="SafeCacheEntry" /> to cache. /// </param> /// <param name="cancellationToken"> /// A cancellation token to cancel the asynchronous operation with. /// </param> /// <returns> /// A task representing the asynchronous operation. /// </returns> /// <exception cref="Gee.External.Browsing.Cache.BrowsingCacheException"> /// Thrown if a caching error occurs. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="safeCacheEntry" /> is a null reference. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// Thrown if the object is disposed. /// </exception> /// <exception cref="System.OperationCanceledException"> /// Thrown if the asynchronous operation is cancelled. /// </exception> public async Task PutSafeCacheEntryAsync(SafeCacheEntry safeCacheEntry, CancellationToken cancellationToken) { this.ThrowIfDisposed(); try { var putSafeCacheEntryTask = this._cache.PutSafeCacheEntryAsync(safeCacheEntry, cancellationToken); await putSafeCacheEntryTask.ConfigureAwait(false); } catch (ArgumentNullException) { throw; } catch (BrowsingCacheException) { throw; } catch (ObjectDisposedException) { this.Dispose(); throw; } catch (OperationCanceledException) { throw; } catch (Exception ex) { const string detailMessage = "A safe cache entry could not be cached."; throw new BrowsingCacheException(detailMessage, ex); } }
public Task PutSafeCacheEntryAsync(SafeCacheEntry safeCacheEntry, CancellationToken cancellationToken) { this.ThrowIfDisposed(); Func <Task> resiliencyPolicyAction = () => this._cache.PutSafeCacheEntryAsync(safeCacheEntry, cancellationToken); var executeResiliencyPolicyTask = this.ExecuteResiliencyPolicyAsync(resiliencyPolicyAction); return(executeResiliencyPolicyTask); }
/// <summary> /// Put a Safe Cache Entry Asynchronously. /// </summary> /// <param name="this"> /// A <see cref="IBrowsingCache" />. /// </param> /// <param name="safeCacheEntry"> /// A <see cref="SafeCacheEntry" /> to cache. /// </param> /// <returns> /// A task representing the asynchronous operation. /// </returns> /// <exception cref="Gee.External.Browsing.Cache.BrowsingCacheException"> /// Thrown if a caching error occurs. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="safeCacheEntry" /> is a null reference. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// Thrown if <paramref name="this" /> is disposed. /// </exception> public static Task PutSafeCacheEntryAsync(this IBrowsingCache @this, SafeCacheEntry safeCacheEntry) { Guard.ThrowIf(nameof(@this), @this).Null(); // ... // // Throws an exception if the operation fails. var putSafeCacheEntryTask = @this.PutSafeCacheEntryAsync(safeCacheEntry, CancellationToken.None); return(putSafeCacheEntryTask); }
/// <summary> /// Put a Safe Cache Entry Asynchronously. /// </summary> /// <param name="this"> /// A <see cref="IBrowsingCache" />. /// </param> /// <param name="threatSha256HashPrefix"> /// A SHA256 hash prefix, formatted as a hexadecimal encoded string, identifying a threat to cache. /// </param> /// <param name="expirationDate"> /// The date, in Coordinated Universal Time (UTC), the safe cache entry expires and the threat identified /// by <paramref name="threatSha256HashPrefix" /> should be considered safe to. If the date is not in UTC, /// it is converted to it. /// </param> /// <param name="cancellationToken"> /// A cancellation token to cancel the asynchronous operation with. /// </param> /// <returns> /// A task representing the asynchronous operation. /// </returns> /// <exception cref="Gee.External.Browsing.Cache.BrowsingCacheException"> /// Thrown if a caching error occurs. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="this" /> is a null reference, or if /// <paramref name="threatSha256HashPrefix" /> is a null reference. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// Thrown if the object is disposed. /// </exception> /// <exception cref="System.OperationCanceledException"> /// Thrown if the asynchronous operation is cancelled. /// </exception> public static Task PutSafeCacheEntryAsync(this IBrowsingCache @this, string threatSha256HashPrefix, DateTime expirationDate, CancellationToken cancellationToken) { Guard.ThrowIf(nameof(@this), @this).Null(); // ... // // Throws an exception if the operation fails. var safeCacheEntry = new SafeCacheEntry(threatSha256HashPrefix, expirationDate); var putSafeCacheEntryTask = @this.PutSafeCacheEntryAsync(safeCacheEntry, cancellationToken); return(putSafeCacheEntryTask); }
public Task PutSafeCacheEntryAsync(SafeCacheEntry safeCacheEntry, CancellationToken cancellationToken) { this.ThrowIfDisposed(); // ... // // Throws an exception if the operation fails. var threatSha256HashPrefix = safeCacheEntry?.ThreatSha256HashPrefix; this._safeCache.AddOrUpdate(threatSha256HashPrefix, safeCacheEntry, (k, v) => safeCacheEntry); return(Task.CompletedTask); }