Skip to content

Commit

Permalink
Synchronize LruKeyCache.Clear (#3361)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaszRozmej authored Aug 31, 2021
1 parent b525c8e commit 919e4cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/Nethermind/Nethermind.Core/Caching/LruCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ public class LruCache<TKey, TValue> : ICache<TKey, TValue> where TKey : notnull
private readonly Dictionary<TKey, LinkedListNode<LruCacheItem>> _cacheMap;
private readonly LinkedList<LruCacheItem> _lruList;

[MethodImpl(MethodImplOptions.Synchronized)]
public void Clear()
{
_cacheMap?.Clear();
_lruList?.Clear();
}

public LruCache(int maxCapacity, int startCapacity, string name)
{
if (maxCapacity < 1)
Expand All @@ -58,6 +51,13 @@ public LruCache(int maxCapacity, string name)
: this(maxCapacity, 0, name)
{
}

[MethodImpl(MethodImplOptions.Synchronized)]
public void Clear()
{
_cacheMap.Clear();
_lruList.Clear();
}

[MethodImpl(MethodImplOptions.Synchronized)]
public TValue Get(TKey key)
Expand Down
13 changes: 7 additions & 6 deletions src/Nethermind/Nethermind.Core/Caching/LruKeyCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public class LruKeyCache<TKey> where TKey : notnull
private readonly Dictionary<TKey, LinkedListNode<TKey>> _cacheMap;
private readonly LinkedList<TKey> _lruList;

public void Clear()
{
_cacheMap.Clear();
_lruList.Clear();
}

public LruKeyCache(int maxCapacity, int startCapacity, string name)
{
_maxCapacity = maxCapacity;
Expand All @@ -51,6 +45,13 @@ public LruKeyCache(int maxCapacity, string name)
: this(maxCapacity, 0, name)
{
}

[MethodImpl(MethodImplOptions.Synchronized)]
public void Clear()
{
_cacheMap.Clear();
_lruList.Clear();
}

[MethodImpl(MethodImplOptions.Synchronized)]
public bool Get(TKey key)
Expand Down

0 comments on commit 919e4cc

Please sign in to comment.