/// <summary> /// Called when a field type is modified or deleted. /// </summary> /// <param name="fieldTypes">The field types.</param> protected void InvalidateFieldTypes(IEnumerable <long> fieldTypes) { IList <TKey> fieldTypesKeys; fieldTypesKeys = fieldTypes.SelectMany(relType => FieldTypeToCacheKey.GetValues(relType)).Distinct( ).ToList( ); InvalidateCacheEntries(fieldTypesKeys, () => string.Format("field {0}", string.Join(",", fieldTypesKeys))); }
/// <summary> /// Raised when items are removed from the cache. /// </summary> /// <param name="sender"> /// The object that raised the event. /// </param> /// <param name="itemsRemovedEventArgs"> /// Event-specific args. /// </param> private void CacheOnItemsRemoved(object sender, ItemsRemovedEventArgs <TKey> itemsRemovedEventArgs) { // Items are removed here to ensure the CacheInvalidator handles // cases where items are removed from the cache outside invalidation, e.g. // LRU cache or timeout cache. EntityToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); FieldTypeToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); RelationshipTypeToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); EntityInvalidatingRelationshipTypesToCacheKey.RemoveValues(itemsRemovedEventArgs.Items); }
/// <summary> /// Set the invalidating entities, relationships and /// fields from the <see cref="CacheContext"/>. /// </summary> /// <param name="cacheContext"> /// The <see cref="CacheContext"/> /// </param> /// <param name="key"> /// The key to associate the entities, relationships and fields with. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="cacheContext"/> cannot be null. /// </exception> public void AddInvalidations(CacheContext cacheContext, TKey key) { if (cacheContext == null) { throw new ArgumentNullException("cacheContext"); } EntityToCacheKey.AddOrUpdateKeys(cacheContext.Entities, key); FieldTypeToCacheKey.AddOrUpdateKeys(cacheContext.FieldTypes, key); RelationshipTypeToCacheKey.AddOrUpdateKeys(cacheContext.RelationshipTypes, key); EntityInvalidatingRelationshipTypesToCacheKey.AddOrUpdateKeys(cacheContext.EntityInvalidatingRelationshipTypes, key); EntityTypeToCacheKey.AddOrUpdateKeys(cacheContext.EntityTypes, key); }
/// <summary> /// Extract the cache invalidation values for the specified key into a serializable structure. /// </summary> /// <param name="key">The key.</param> /// <returns> /// A serializable structure containing the values for the specified invalidation key /// </returns> /// <exception cref="System.ArgumentNullException">key</exception> public Lazy <SerializableCacheInvalidationKey <TKey> > ToSerializableKey(TKey key) { if (Equals(key, null)) { throw new ArgumentNullException("key"); } return(new Lazy <SerializableCacheInvalidationKey <TKey> >(() => { var serializableKey = new SerializableCacheInvalidationKey <TKey>(Name, key) { EntityToCacheKey = EntityToCacheKey.GetKeys(key), FieldTypeToCacheKey = FieldTypeToCacheKey.GetKeys(key), RelationshipTypeToCacheKey = RelationshipTypeToCacheKey.GetKeys(key), EntityInvalidatingRelationshipTypesToCacheKey = EntityInvalidatingRelationshipTypesToCacheKey.GetKeys(key), EntityTypeToCacheKey = EntityTypeToCacheKey.GetKeys(key) }; return serializableKey; }, false)); }
/// <summary> /// Merge the values for the specified serializable cache invalidation key with those already present. /// </summary> /// <param name="lazySerializableKey">The lazy serializable key.</param> public void FromSerializableKey(Lazy <SerializableCacheInvalidationKey <TKey> > lazySerializableKey) { if (lazySerializableKey == null) { return; } var serializableKey = lazySerializableKey.Value; if (serializableKey == null) { return; } if (serializableKey.EntityToCacheKey != null) { EntityToCacheKey.AddOrUpdateKeys(serializableKey.EntityToCacheKey, serializableKey.Key); } if (serializableKey.FieldTypeToCacheKey != null) { FieldTypeToCacheKey.AddOrUpdateKeys(serializableKey.FieldTypeToCacheKey, serializableKey.Key); } if (serializableKey.RelationshipTypeToCacheKey != null) { RelationshipTypeToCacheKey.AddOrUpdateKeys(serializableKey.RelationshipTypeToCacheKey, serializableKey.Key); } if (serializableKey.EntityInvalidatingRelationshipTypesToCacheKey != null) { EntityInvalidatingRelationshipTypesToCacheKey.AddOrUpdateKeys(serializableKey.EntityInvalidatingRelationshipTypesToCacheKey, serializableKey.Key); } if (serializableKey.EntityTypeToCacheKey != null) { EntityTypeToCacheKey.AddOrUpdateKeys(serializableKey.EntityTypeToCacheKey, serializableKey.Key); } }