public void InvalidateSets(IEnumerable <string> entitySets) { // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null entitySets.GuardAgainstNull(nameof(entitySets)); _database = _redis.GetDatabase(); var itemsToInvalidate = new HashSet <string>(); lock (_lock) { try { // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null foreach (var entitySet in entitySets) { var entitySetKey = AddCacheQualifier(entitySet); var keys = _database.SetMembers(entitySetKey).Select(v => v.ToString()); itemsToInvalidate.UnionWith(keys); _database.KeyDelete(entitySetKey, CommandFlags.FireAndForget); } } catch (Exception e) { OnCachingFailed(e); return; } foreach (var key in itemsToInvalidate) { InvalidateItem(key); } } }
public void PutItem(string key, object value, IEnumerable <string> dependentEntitySets, TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration) { key.GuardAgainstNullOrEmpty(nameof(key)); // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null dependentEntitySets.GuardAgainstNull(nameof(dependentEntitySets)); _database = _redis.GetDatabase(); key = HashKey(key); // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null var entitySets = dependentEntitySets.ToArray(); lock (_lock) { try { foreach (var entitySet in entitySets) { _database.SetAdd(AddCacheQualifier(entitySet), key, CommandFlags.FireAndForget); } _database.Set(key, new CacheEntry(value, entitySets, slidingExpiration, absoluteExpiration)); } catch (Exception e) { OnCachingFailed(e); } } }
public InProcessChangeEventNotificationSubscription(ILogger logger, IChangeEventMigrator migrator, IEnumerable <IDomainEventPublisherSubscriberPair> pubSubPairs, params IEventNotifyingStorage[] eventingStorages) : base(logger, eventingStorages) { logger.GuardAgainstNull(nameof(logger)); migrator.GuardAgainstNull(nameof(migrator)); pubSubPairs.GuardAgainstNull(nameof(pubSubPairs)); this.notificationProducer = new DomainEventNotificationProducer(logger, migrator, pubSubPairs.ToArray()); }
public InProcessReadModelProjectionSubscription(ILogger logger, IIdentifierFactory idFactory, IChangeEventMigrator migrator, IDomainFactory domainFactory, IRepository repository, IEnumerable <IReadModelProjection> projections, params IEventNotifyingStorage[] eventingStorages) : base(logger, eventingStorages) { logger.GuardAgainstNull(nameof(logger)); idFactory.GuardAgainstNull(nameof(idFactory)); migrator.GuardAgainstNull(nameof(migrator)); domainFactory.GuardAgainstNull(nameof(domainFactory)); repository.GuardAgainstNull(nameof(repository)); projections.GuardAgainstNull(nameof(projections)); var checkpointReadModel = new ReadModelCheckpointStore(logger, idFactory, domainFactory, repository); this.projector = new ReadModelProjector(logger, checkpointReadModel, migrator, projections?.ToArray()); }
private IDictionary <string, string> InitializeSubstitutions(IEnumerable <string> values) { values.GuardAgainstNull(nameof(values)); var result = new Dictionary <string, string>(); var substitutions = Substitutions.ToList(); var counter = 0; values.ToList().ForEach(val => { if (substitutions.Count > counter) { result.Add(substitutions[counter], val); counter++; } }); return(result); }
/// <summary> /// Since a sql database write is about to happen, remove all cached sql query results referencing the provided /// entity sets (tables). Then remove the actual entity set values. /// Use a Lua script to ensure that this operation happens atomically. /// </summary> /// <param name="entitySets">The entity sets used by the sql insert, update, delete being issued</param> public void InvalidateSets(IEnumerable <string> entitySets) { // ReSharper disable PossibleMultipleEnumeration entitySets.GuardAgainstNull(nameof(entitySets)); var database = Connection.GetDatabase(); var setKeys = entitySets.Select(AddCacheQualifier); var queryKeys = new HashSet <string>(); PerformWithRetryBackoff(() => { var result = database.ScriptEvaluate(_invalidateSetsScriptSha1, setKeys.ToArray()); // Result is the set of keys for the queries that were removed. Used below for stats foreach (var queryKey in (string[])result) { queryKeys.Add(queryKey); } return(null); }); // ReSharper restore PossibleMultipleEnumeration if (!ShouldCollectStatistics) { return; } // Update the stats for the entity sets to indicate the whole set was invalidated foreach (var setKey in setKeys) { database.HashIncrement(AddStatsQualifier(HashKey(setKey)), InvalidationsIdentifier, 1, CommandFlags.FireAndForget); } // Update the stats for the queries removed from Redis indicating they were invalidated foreach (var hashedKey in queryKeys) { database.HashIncrement(AddStatsQualifier(hashedKey), InvalidationsIdentifier, 1, CommandFlags.FireAndForget); } }
public void InvalidateSets(IEnumerable<string> entitySets) { // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null entitySets.GuardAgainstNull(nameof(entitySets)); _database = _redis.GetDatabase(); var itemsToInvalidate = new HashSet<string>(); lock (_lock) { try { // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null foreach (var entitySet in entitySets) { var entitySetKey = AddCacheQualifier(entitySet); var keys = _database.SetMembers(entitySetKey).Select(v => v.ToString()); itemsToInvalidate.UnionWith(keys); _database.KeyDelete(entitySetKey, CommandFlags.FireAndForget); } } catch (Exception e) { OnCachingFailed(e); return; } foreach (var key in itemsToInvalidate) { InvalidateItem(key); } } }
public void PutItem(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration) { key.GuardAgainstNullOrEmpty(nameof(key)); // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null dependentEntitySets.GuardAgainstNull(nameof(dependentEntitySets)); _database = _redis.GetDatabase(); key = HashKey(key); // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null var entitySets = dependentEntitySets.ToArray(); lock (_lock) { try { foreach (var entitySet in entitySets) { _database.SetAdd(AddCacheQualifier(entitySet), key, CommandFlags.FireAndForget); } _database.Set(key, new CacheEntry(value, entitySets, slidingExpiration, absoluteExpiration)); } catch (Exception e) { OnCachingFailed(e); } } }