예제 #1
0
        private async Task SetValueAsyncCore(TKey key, Stream value)
        {
            var result = await SetValueCoreAsync(key, value).ConfigureAwait(false);

            switch (result)
            {
            case SetStatus.DataTooLarge:
                throw new ArgumentException("The given stream received data that was larger than the allotted storage capacity of " + MaximumStorageCapacity.ToString(CultureInfo.InvariantCulture), nameof(value));
            }
        }
예제 #2
0
        /// <summary>
        /// Stores a value associated with a key.
        /// </summary>
        /// <param name="key">The key used to locate the value in the cache.</param>
        /// <param name="value">A stream of data to store in the cache.</param>
        /// <exception cref="ArgumentNullException"><paramref name="key"/> is <c>null</c> or <paramref name="value"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="value"/> is not readable.</exception>
        public void SetValue(TKey key, Stream value)
        {
            if (IsNull(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (!value.CanRead)
            {
                throw new ArgumentException("The given stream is not readable.", nameof(value));
            }

            var result = SetValueCore(key, value);

            switch (result)
            {
            case SetStatus.DataTooLarge:
                throw new ArgumentException("The given stream received data that was larger than the allotted storage capacity of " + MaximumStorageCapacity.ToString(CultureInfo.InvariantCulture), nameof(value));
            }
        }