Skip to content

Commit

Permalink
Add additional thread-safety guarantees to Cache class. (#2306)
Browse files Browse the repository at this point in the history
Co-authored-by: Eddy Nakamura <eddynaka@gmail.com>
  • Loading branch information
michaelcfanning and eddynaka authored Mar 3, 2021
1 parent 19b010c commit 46b26e5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Sarif/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,22 @@ private void SetValue(TKey key, TValue value)
/// <returns>True if value in cache, False otherwise</returns>
public bool ContainsKey(TKey key)
{
return _cache.ContainsKey(key);
lock (_keysInUseOrder)
{
return _cache.ContainsKey(key);
}
}

/// <summary>
/// Clear current cache.
/// </summary>
public void Clear()
{
this._cache.Clear();
this._keysInUseOrder.Clear();
lock (_keysInUseOrder)
{
this._cache.Clear();
this._keysInUseOrder.Clear();
}
}
}
}

0 comments on commit 46b26e5

Please sign in to comment.