src/SyncTool.Utilities/main/CachingObjectMapper.cs
/// <summary>
/// Removes cached values for all objects not present in the specified list from the cache
/// </summary>
/// <param name="currentItems"></param>
Removes cached values for all objects not present in the specified list from the cache
Removes cached values for all objects not present in the specified list from the cache
public void CleanCache(IEnumerable<TSource> currentItems, bool disposeMappedObjects = true)
        {            
            var itemSet = new HashSet<TSource>(currentItems, m_EqualityComparer);
            var keysToRemove = m_Cache.Keys.Where(key => itemSet.Contains(key) == false).ToList();
            foreach (var key in keysToRemove)
            {
                var value = m_Cache[key];
                if (disposeMappedObjects && value is IDisposable disposable)
                {
                    disposable.Dispose();
                }
                m_Cache.Remove(key);
            }            
        }
public void CleanCache ( IEnumerable < TSource > currentItems , bool disposeMappedObjects = true ) { var itemSet = new HashSet < TSource > ( currentItems , m_EqualityComparer ) ; var keysToRemove = m_Cache . Keys . Where ( key => itemSet . Contains ( key ) == false ) . ToList ( ) ; foreach ( var key in keysToRemove ) { var value = m_Cache [ key ] ; if ( disposeMappedObjects && value is IDisposable disposable ) { disposable . Dispose ( ) ; } m_Cache . Remove ( key ) ; } }
Removes cached values for all objects not present in the specified list from the cache
Removes cached values for all objects not present in the specified list from the cache
currentItems
IEnumerable<TSource>
None
disposeMappedObjects
bool