Skip to content

Commit

Permalink
housekeeping: Keep users from breaking with a runtime constructor cha…
Browse files Browse the repository at this point in the history
…nge (#345)
  • Loading branch information
glennawatson committed Jun 21, 2019
1 parent 161eeda commit 8999eb2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Expand Up @@ -663,7 +663,10 @@ namespace Splat
}
public sealed class MemoizingMRUCache<TParam, TVal>
{
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Action<TVal> onRelease = null, System.Collections.Generic.IEqualityComparer<TParam> paramComparer = null) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Action<TVal> onRelease) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Collections.Generic.IEqualityComparer<TParam> paramComparer) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Action<TVal> onRelease, System.Collections.Generic.IEqualityComparer<TParam> paramComparer) { }
public System.Collections.Generic.IEnumerable<TVal> CachedValues() { }
public TVal Get(TParam key) { }
public TVal Get(TParam key, object context = null) { }
Expand Down
Expand Up @@ -652,7 +652,10 @@ namespace Splat
}
public sealed class MemoizingMRUCache<TParam, TVal>
{
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Action<TVal> onRelease = null, System.Collections.Generic.IEqualityComparer<TParam> paramComparer = null) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Action<TVal> onRelease) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Collections.Generic.IEqualityComparer<TParam> paramComparer) { }
public MemoizingMRUCache(System.Func<TParam, object, TVal> calculationFunc, int maxSize, System.Action<TVal> onRelease, System.Collections.Generic.IEqualityComparer<TParam> paramComparer) { }
public System.Collections.Generic.IEnumerable<TVal> CachedValues() { }
public TVal Get(TParam key) { }
public TVal Get(TParam key, object context = null) { }
Expand Down
45 changes: 44 additions & 1 deletion src/Splat/MemoizingMRUCache.cs
Expand Up @@ -35,6 +35,49 @@ public sealed class MemoizingMRUCache<TParam, TVal>
private LinkedList<TParam> _cacheMRUList;
private Dictionary<TParam, (LinkedListNode<TParam> param, TVal value)> _cacheEntries;

/// <summary>
/// Initializes a new instance of the <see cref="MemoizingMRUCache{TParam, TVal}"/> class.
/// </summary>
/// <param name="calculationFunc">The function whose results you want to cache,
/// which is provided the key value, and an Tag object that is
/// user-defined.</param>
/// <param name="maxSize">The size of the cache to maintain, after which old
/// items will start to be thrown out.</param>
public MemoizingMRUCache(Func<TParam, object, TVal> calculationFunc, int maxSize)
: this(calculationFunc, maxSize, null, EqualityComparer<TParam>.Default)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MemoizingMRUCache{TParam, TVal}"/> class.
/// </summary>
/// <param name="calculationFunc">The function whose results you want to cache,
/// which is provided the key value, and an Tag object that is
/// user-defined.</param>
/// <param name="maxSize">The size of the cache to maintain, after which old
/// items will start to be thrown out.</param>
/// <param name="onRelease">A function to call when a result gets
/// evicted from the cache (i.e. because Invalidate was called or the
/// cache is full).</param>
public MemoizingMRUCache(Func<TParam, object, TVal> calculationFunc, int maxSize, Action<TVal> onRelease)
: this(calculationFunc, maxSize, onRelease, EqualityComparer<TParam>.Default)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MemoizingMRUCache{TParam, TVal}"/> class.
/// </summary>
/// <param name="calculationFunc">The function whose results you want to cache,
/// which is provided the key value, and an Tag object that is
/// user-defined.</param>
/// <param name="maxSize">The size of the cache to maintain, after which old
/// items will start to be thrown out.</param>
/// <param name="paramComparer">A comparer for the parameter.</param>
public MemoizingMRUCache(Func<TParam, object, TVal> calculationFunc, int maxSize, IEqualityComparer<TParam> paramComparer)
: this(calculationFunc, maxSize, null, paramComparer)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MemoizingMRUCache{TParam, TVal}"/> class.
/// </summary>
Expand All @@ -47,7 +90,7 @@ public sealed class MemoizingMRUCache<TParam, TVal>
/// evicted from the cache (i.e. because Invalidate was called or the
/// cache is full).</param>
/// <param name="paramComparer">A comparer for the parameter.</param>
public MemoizingMRUCache(Func<TParam, object, TVal> calculationFunc, int maxSize, Action<TVal> onRelease = null, IEqualityComparer<TParam> paramComparer = null)
public MemoizingMRUCache(Func<TParam, object, TVal> calculationFunc, int maxSize, Action<TVal> onRelease, IEqualityComparer<TParam> paramComparer)
{
Contract.Requires(calculationFunc != null);
Contract.Requires(maxSize > 0);
Expand Down

0 comments on commit 8999eb2

Please sign in to comment.