Exemple #1
0
        private static async Task RunSetMapSamplesAsync(ISetMap <Guid, Data> setMap)
        {
            var id   = Guid.NewGuid();
            var data = new Data()
            {
                Name = "A name", Value = 5
            };

            // A SetMap is a map of sets items with special extensions methods
            // Uses an extension method that adds an item to a set in the key
            await setMap.AddItemAsync(id, data);

            var set = await setMap.GetValueOrDefaultAsync(id);

            if (await set.ContainsAsync(data))
            {
                Console.WriteLine($"The value '{data}' is present in the set");
            }

            // Removes the item from the set map
            if (await setMap.TryRemoveItemAsync(id, data))
            {
                Console.WriteLine($"The item of the set in the key '{id}' was removed");
            }
        }
Exemple #2
0
 public ScopedSetMap(ISetMap <TKey, TItem> map, IScope scope, string identifier, ISerializer <TKey> keySerializer, bool removeOnEmptySet = false)
     : base(map, scope, identifier, keySerializer)
 {
     _scope            = (MapScope)scope;
     _keySerializer    = keySerializer;
     _removeOnEmptySet = removeOnEmptySet;
 }
        /// <summary>
        /// Checks if the key exists and the value exists in the set.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TItem">The type of the item.</typeparam>
        /// <param name="setMap">The set map.</param>
        /// <param name="key">The key.</param>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static async Task <bool> ContainsItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap, TKey key,
                                                                        TItem item)
        {
            var set = await setMap.GetValueOrEmptyAsync(key).ConfigureAwait(false);

            return(await set.ContainsAsync(item).ConfigureAwait(false));
        }
Exemple #4
0
        /// <summary>
        /// Checks if the key exists and the value exists in the set.
        /// </summary>
        public static async Task <bool> ContainsItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap,
                                                                        TKey key,
                                                                        TItem item,
                                                                        CancellationToken cancellationToken = default)
        {
            var set = await setMap.GetValueOrEmptyAsync(key, cancellationToken).ConfigureAwait(false);

            return(await set.ContainsAsync(item, cancellationToken).ConfigureAwait(false));
        }
Exemple #5
0
        /// <summary>
        /// Adds an item to the set.
        /// If the key doesn't exists, it will be created.
        /// If the value already exists, it is overwritten.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TItem">The type of the item.</typeparam>
        /// <param name="setMap">The set map.</param>
        /// <param name="key">The key.</param>
        /// <param name="item">The item.</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task AddItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap,
                                                            TKey key,
                                                            TItem item,
                                                            CancellationToken cancellationToken = default)
        {
            var set = await setMap.GetValueOrEmptyAsync(key, cancellationToken).ConfigureAwait(false);

            await set.AddAsync(item, cancellationToken).ConfigureAwait(false);
        }
Exemple #6
0
        /// <summary>
        /// Adds some items to the set.
        /// If the key doesn't exists, it will be created.
        /// If the value already exists, it is overwritten.
        /// </summary>
        public static async Task AddItemsAsync <TKey, TItem>(
            this ISetMap <TKey, TItem> setMap,
            TKey key,
            IAsyncEnumerable <TItem> items,
            CancellationToken cancellationToken = default)
        {
            var set = await setMap.GetValueOrEmptyAsync(key, cancellationToken).ConfigureAwait(false);

            await set.AddRangeAsync(items, cancellationToken).ConfigureAwait(false);
        }
        public DistributedCacheSetMap(
            ISetMap <TKey, TValue> source,
            ISetMap <TKey, TValue> cache,
            IBus <string, SynchronizationEvent <TKey> > synchronizationBus,
            string synchronizationChannel,
            TimeSpan cacheExpiration     = default,
            TimeSpan cacheFaultTolerance = default)
        {
            var onDemandCacheSetMap = new OnDemandCacheSetMap <TKey, TValue>(source, cache, cacheExpiration, cacheFaultTolerance);

            _strategy         = new DistributedCacheStrategy <TKey, ISet <TValue> >(cache, synchronizationBus, synchronizationChannel);
            _underlyingSetMap = new NotifyWriteSetMap <TKey, TValue>(onDemandCacheSetMap, _strategy.PublishEventAsync);
        }
Exemple #8
0
 public MapScope(string name, ISetMap <string, IdentifierKey> keysSetMap)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     if (keysSetMap == null)
     {
         throw new ArgumentNullException(nameof(keysSetMap));
     }
     Name                = name;
     KeysSetMap          = keysSetMap;
     ScopedMapDictionary = new Dictionary <string, IScopedMap>();
 }
        /// <summary>
        /// Adds an item to the set.
        /// If the key doesn't exists, it will be created.
        /// If the value already exists, it is overwritten.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TItem">The type of the item.</typeparam>
        /// <param name="setMap">The set map.</param>
        /// <param name="key">The key.</param>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static async Task AddItemAsync <TKey, TItem>(this ISetMap <TKey, TItem> setMap, TKey key, TItem item)
        {
            var set = await setMap.GetValueOrEmptyAsync(key).ConfigureAwait(false);

            await set.AddAsync(item).ConfigureAwait(false);
        }
Exemple #10
0
 public ReplicationSetMap(ISetMap <TKey, TValue> master, ISetMap <TKey, TValue> slave, TimeSpan synchronizationTimeout) : base(master, slave, synchronizationTimeout)
 {
 }
Exemple #11
0
 public virtual MapScope CreateMapScope(string scopeName, ISetMap <string, IdentifierKey> keysSetMap)
 {
     return(new MapScope(scopeName, keysSetMap));
 }
Exemple #12
0
 protected CacheSetMap(ISetMap <TKey, TValue> source, ISetMap <TKey, TValue> cache, ISynchronizer <IMap <TKey, ISet <TValue> > > synchronizer, TimeSpan cacheExpiration = default(TimeSpan))
     : base(source, cache, synchronizer, cacheExpiration)
 {
 }
Exemple #13
0
 public CacheSetMap(ISetMap <TKey, TValue> source, ISetMap <TKey, TValue> cache, TimeSpan synchronizationTimeout, TimeSpan cacheExpiration = default(TimeSpan))
     : base(source, cache, synchronizationTimeout, cacheExpiration)
 {
 }
Exemple #14
0
 public OnDemandCacheSetMap(ISetMap <TKey, TValue> source, ISetMap <TKey, TValue> cache, TimeSpan cacheExpiration = default(TimeSpan))
     : base(source, cache, cacheExpiration)
 {
 }
Exemple #15
0
 public OnDemandCacheSetMap(ISetMap <TKey, TValue> source, ISetMap <TKey, TValue> cache, TimeSpan cacheExpiration = default, TimeSpan cacheFaultTolerance = default)
     : base(source, cache, cacheExpiration, cacheFaultTolerance)
 {
 }
Exemple #16
0
 public BackupSetMap(ISetMap <TKey, TValue> primary, ISetMap <TKey, TValue> backup, ISynchronizer <IMap <TKey, ISet <TValue> > > synchronizer)
     : base(primary, backup, synchronizer)
 {
 }
Exemple #17
0
 public BackupSetMap(ISetMap <TKey, TValue> primary, ISetMap <TKey, TValue> backup, TimeSpan synchronizationTimeout)
     : base(primary, backup, synchronizationTimeout)
 {
 }
 public NotifyWriteSetMap(ISetMap <TKey, TValue> setMap, Func <TKey, CancellationToken, Task> writeHandler)
 {
     _setMap         = setMap ?? throw new ArgumentNullException(nameof(setMap));
     _writeHandler   = writeHandler ?? throw new ArgumentNullException(nameof(writeHandler));
     _notifyWriteMap = new NotifyWriteMap <TKey, ISet <TValue> >(setMap, writeHandler);
 }
Exemple #19
0
 public ReplicationSetMap(ISetMap <TKey, TValue> master, ISetMap <TKey, TValue> slave, ISynchronizer <IMap <TKey, ISet <TValue> > > synchronizer) : base(master, slave, synchronizer)
 {
 }