Example #1
0
        /// <summary>
        /// Adds the specified <paramref name="keyValuePairs" /> to the <paramref name="cache"/>
        /// with their expiry set to <see cref="TimeSpan.MaxValue" /> and <see cref="ObservableCacheExpirationType" /> to <see cref="ObservableCacheExpirationType.DoNothing" />.
        /// </summary>
        /// <param name="cache">The cache to use.</param>
        /// <param name="keyValuePairs">The key/value pairs to add.</param>
        /// <param name="scheduler">Scheduler to perform the addrange action on.</param>
        /// <returns>
        /// An observable stream that returns an <see cref="Unit" /> for every added element of the <paramref name="keyValuePairs"/>.
        /// </returns>
        public static IObservable <KeyValuePair <TKey, TValue> > AddRange <TKey, TValue>(this IObservableCache <TKey, TValue> cache, IEnumerable <KeyValuePair <TKey, TValue> > keyValuePairs, IScheduler scheduler = null)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }
            if (keyValuePairs == null)
            {
                throw new ArgumentNullException(nameof(keyValuePairs));
            }

            return(cache.AddRange(keyValuePairs, TimeSpan.MaxValue, ObservableCacheExpirationType.DoNothing, scheduler));
        }
Example #2
0
        /// <summary>
        /// Adds the specified <paramref name="keyValuePairs" /> to the <see cref="IObservableCache{TKey,TValue}" />.
        /// </summary>
        /// <param name="cache">The cache to use.</param>
        /// <param name="keyValuePairs">The key/value pairs to add.</param>
        /// <param name="expiry">The expiry of the <paramref name="keyValuePairs" />.</param>
        /// <param name="expirationType">Defines how the <paramref name="keyValuePairs" /> shall expire.</param>
        /// <param name="scheduler">Scheduler to perform the addrange action on.</param>
        /// <returns>
        /// An observable stream that returns an <see cref="Unit" /> for every added element of the <paramref name="keyValuePairs"/>.
        /// </returns>
        public static IObservable <KeyValuePair <TKey, TValue> > AddRange <TKey, TValue>(this IObservableCache <TKey, TValue> cache, IEnumerable <KeyValuePair <TKey, TValue> > keyValuePairs, TimeSpan expiry, ObservableCacheExpirationType expirationType = ObservableCacheExpirationType.DoNothing, IScheduler scheduler = null)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }
            if (keyValuePairs == null)
            {
                throw new ArgumentNullException(nameof(keyValuePairs));
            }

            var keyValuePairsAsList = keyValuePairs.ToList();

            if (keyValuePairsAsList.Count == 0)
            {
                return(scheduler != null
                    ? Observable.Empty <KeyValuePair <TKey, TValue> >(scheduler)
                    : Observable.Empty <KeyValuePair <TKey, TValue> >());
            }

            return(cache.AddRange(keyValuePairsAsList.AsObservable(scheduler), expiry, expirationType, scheduler));
        }