/// <summary> /// Asynchronously sets a string in the specified cache with the specified key. /// </summary> /// <param name="cache">The cache in which to store the data.</param> /// <param name="key">The key to store the data in.</param> /// <param name="value">The data to store in the cache.</param> /// <param name="options">The cache options for the entry.</param> /// <param name="token">Optional. A <see cref="CancellationToken" /> to cancel the operation.</param> /// <returns>A task that represents the asynchronous set operation.</returns> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception> public static Task SetStringAsync(this LucidCache cache, string key, string value, DistributedCacheEntryOptions options, CancellationToken token = default(CancellationToken)) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } return(cache.SetAsync(key, Encoding.UTF8.GetBytes(value), options, token)); }
/// <summary> /// Asynchronously sets a sequence of bytes in the specified cache with the specified key. /// </summary> /// <param name="cache">The cache in which to store the data.</param> /// <param name="key">The key to store the data in.</param> /// <param name="value">The data to store in the cache.</param> /// <param name="token">Optional. A <see cref="CancellationToken" /> to cancel the operation.</param> /// <returns>A task that represents the asynchronous set operation.</returns> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception> public static Task SetAsync(this LucidCache cache, string key, byte[] value, CancellationToken token = default(CancellationToken)) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } return(cache.SetAsync(key, value, new DistributedCacheEntryOptions(), token)); }