diff --git a/src/NLog/Internal/MruCache.cs b/src/NLog/Internal/MruCache.cs index 215727b135..067d8d5f45 100644 --- a/src/NLog/Internal/MruCache.cs +++ b/src/NLog/Internal/MruCache.cs @@ -40,38 +40,38 @@ namespace NLog.Internal /// internal class MruCache { - private readonly Dictionary _dictionary; + private readonly Dictionary _dictionary; private readonly int _maxCapacity; private long _currentVersion; /// /// Constructor /// - /// Max number of items to hold before discarding + /// Maximum number of items the cache will hold before discarding. public MruCache(int maxCapacity) { _maxCapacity = maxCapacity; - _dictionary = new Dictionary(_maxCapacity); + _dictionary = new Dictionary(_maxCapacity); _currentVersion = 1; } /// - /// Insert item into caceh + /// Attempt to insert item into cache. /// - /// Dictionary Key - /// Dictionary Value - /// Key did not exist already + /// Key of the item to be inserted in the cache. + /// Value of the item to be inserted in the cache. + /// true when the key does not already exist in the cache, false otherwise. public bool TryAddValue(TKey key, TValue value) { lock (_dictionary) { - MruItem item; + MruCacheItem item; if (_dictionary.TryGetValue(key, out item)) { var version = _currentVersion; if (item.Version != version || !EqualityComparer.Default.Equals(value, item.Value)) { - _dictionary[key] = new MruItem(value, version, false); + _dictionary[key] = new MruCacheItem(value, version, false); } return false; // Already exists } @@ -83,7 +83,7 @@ public bool TryAddValue(TKey key, TValue value) PruneCache(); } - _dictionary.Add(key, new MruItem(value, _currentVersion, true)); + _dictionary.Add(key, new MruCacheItem(value, _currentVersion, true)); return true; } } @@ -147,14 +147,14 @@ private void PruneCache() } /// - /// Lookup existing item in cache + /// Lookup existing item in cache. /// - /// Dictionary Key - /// Dictionary Value [out] - /// Key found + /// Key of the item to be searched in the cache. + /// Output value of the item found in the cache. + /// True when the key is found in the cache, false otherwise. public bool TryGetValue(TKey key, out TValue value) { - MruItem item; + MruCacheItem item; try { if (!_dictionary.TryGetValue(key, out item)) @@ -165,7 +165,7 @@ public bool TryGetValue(TKey key, out TValue value) } catch { - item = default(MruItem); // Too many people in the same room + item = default(MruCacheItem); // Too many people in the same room } if (item.Version != _currentVersion || item.Virgin) @@ -182,7 +182,7 @@ public bool TryGetValue(TKey key, out TValue value) { version = ++_currentVersion; } - _dictionary[key] = new MruItem(item.Value, version, false); + _dictionary[key] = new MruCacheItem(item.Value, version, false); } } else @@ -197,13 +197,13 @@ public bool TryGetValue(TKey key, out TValue value) return true; } - struct MruItem + struct MruCacheItem { - public readonly TValue Value; - public readonly long Version; - public readonly bool Virgin; + public TValue Value { get; } + public long Version { get; } + public bool Virgin { get; } - public MruItem(TValue value, long version, bool virgin) + public MruCacheItem(TValue value, long version, bool virgin) { Value = value; Version = version;