Skip to content

Commit

Permalink
Fix exception message and quick list down sizing on empty cache
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-sunset committed Jun 6, 2022
1 parent 86d6f44 commit f7260ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/FastCache.Cached/Collections/CachedRange.Impl.cs
Expand Up @@ -256,8 +256,8 @@ private static uint GetParallelism(uint length)
}

[DoesNotReturn]
private static void RangeMismatch(int keys, int values)
private static void IncorrectLength(int keys, int values)
{
throw new ArgumentOutOfRangeException($"Cannot perform 'Save()' for provided ranges - length mismatch, keys: {keys}, values: {values}.");
throw new ArgumentOutOfRangeException(nameof(values), values, $"Cannot perform 'Save()' for provided ranges - length mismatch. Expected: {keys}.");
}
}
15 changes: 6 additions & 9 deletions src/FastCache.Cached/Collections/CachedRange.cs
Expand Up @@ -38,7 +38,7 @@ public static partial class CachedRange
var length = keys.Length;
if (length < 0 || length != values.Length)
{
RangeMismatch(length, values.Length);
IncorrectLength(length, values.Length);
}

var parallelism = GetParallelism((uint)length);
Expand Down Expand Up @@ -73,16 +73,13 @@ public static partial class CachedRange
SaveListMultithreaded<K, V, IList<(K, V)>>(range, expiration, (int)parallelism);
}
}
else if (range is List<(K, V)> list)
{
SaveListSinglethreaded<K, V, List<(K, V)>>(list, expiration);
}
else
{
if (range is List<(K, V)> list)
{
SaveListSinglethreaded<K, V, List<(K, V)>>(list, expiration);
}
else
{
SaveListSinglethreaded<K, V, IList<(K, V)>>(range, expiration);
}
SaveListSinglethreaded<K, V, IList<(K, V)>>(range, expiration);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/FastCache.Cached/EvictionQuickList.cs
Expand Up @@ -75,7 +75,7 @@ internal bool Evict(bool resize = false)
var totalCount = store.Count;
if (totalCount is 0)
{
if (_inactive.Length != Constants.QuickListMinLength)
if (resize || _inactive.Length != Constants.QuickListMinLength)
{
ResizeInactive(Constants.QuickListMinLength);
AtomicSwapActive(0);
Expand Down

0 comments on commit f7260ce

Please sign in to comment.