diff --git a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet6_0.verified.txt b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet6_0.verified.txt index 4612db9d9..a8350c3f3 100644 --- a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet6_0.verified.txt +++ b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet6_0.verified.txt @@ -1277,19 +1277,13 @@ namespace DynamicData public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector) where TObject : notnull where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.Reactive.Concurrency.IScheduler? scheduler = null) - where TObject : notnull - where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? interval = default) - where TObject : notnull - where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.Reactive.Concurrency.IScheduler scheduler) where TObject : notnull where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.TimeSpan? pollingInterval) where TObject : notnull where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? pollingInterval, System.Reactive.Concurrency.IScheduler? scheduler) + public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? pollingInterval = default, System.Reactive.Concurrency.IScheduler? scheduler = null) where TObject : notnull where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.TimeSpan? pollingInterval, System.Reactive.Concurrency.IScheduler scheduler) diff --git a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet7_0.verified.txt b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet7_0.verified.txt index 10b8258c4..0f790bb5c 100644 --- a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet7_0.verified.txt +++ b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet7_0.verified.txt @@ -1277,19 +1277,13 @@ namespace DynamicData public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector) where TObject : notnull where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.Reactive.Concurrency.IScheduler? scheduler = null) - where TObject : notnull - where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? interval = default) - where TObject : notnull - where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.Reactive.Concurrency.IScheduler scheduler) where TObject : notnull where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.TimeSpan? pollingInterval) where TObject : notnull where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? pollingInterval, System.Reactive.Concurrency.IScheduler? scheduler) + public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? pollingInterval = default, System.Reactive.Concurrency.IScheduler? scheduler = null) where TObject : notnull where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.TimeSpan? pollingInterval, System.Reactive.Concurrency.IScheduler scheduler) diff --git a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt index 492b4274f..af6583a04 100644 --- a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt +++ b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt @@ -1277,19 +1277,13 @@ namespace DynamicData public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector) where TObject : notnull where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.Reactive.Concurrency.IScheduler? scheduler = null) - where TObject : notnull - where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? interval = default) - where TObject : notnull - where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.Reactive.Concurrency.IScheduler scheduler) where TObject : notnull where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.TimeSpan? pollingInterval) where TObject : notnull where TKey : notnull { } - public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? pollingInterval, System.Reactive.Concurrency.IScheduler? scheduler) + public static System.IObservable>> ExpireAfter(this DynamicData.ISourceCache source, System.Func timeSelector, System.TimeSpan? pollingInterval = default, System.Reactive.Concurrency.IScheduler? scheduler = null) where TObject : notnull where TKey : notnull { } public static System.IObservable> ExpireAfter(this System.IObservable> source, System.Func timeSelector, System.TimeSpan? pollingInterval, System.Reactive.Concurrency.IScheduler scheduler) diff --git a/src/DynamicData.Tests/Cache/ExpireAfterFixture.cs b/src/DynamicData.Tests/Cache/ExpireAfterFixture.cs index 7fb27b4e1..38dfe3cac 100644 --- a/src/DynamicData.Tests/Cache/ExpireAfterFixture.cs +++ b/src/DynamicData.Tests/Cache/ExpireAfterFixture.cs @@ -29,7 +29,7 @@ public ExpireAfterFixture() [Fact] public void CanHandleABatchOfUpdates() { - var remover = _source.ExpireAfter(p => TimeSpan.FromMilliseconds(100), _scheduler).Subscribe(); + var remover = _source.ExpireAfter(p => TimeSpan.FromMilliseconds(100), scheduler: _scheduler).Subscribe(); const int size = 100; var items = Enumerable.Range(1, size).Select(i => new Person($"Name.{i}", i)).ToArray(); @@ -65,7 +65,7 @@ public void ComplexRemove() var items = Enumerable.Range(1, size).Select(i => new Person($"Name.{i}", i)).ToArray(); _source.AddOrUpdate(items); - var remover = _source.ExpireAfter(RemoveFunc, _scheduler).Subscribe(); + var remover = _source.ExpireAfter(RemoveFunc, scheduler: _scheduler).Subscribe(); _scheduler.AdvanceBy(TimeSpan.FromMilliseconds(5010).Ticks); _source.Count.Should().Be(60, "40 items should have been removed from the cache"); @@ -85,7 +85,7 @@ public void Dispose() [Fact] public void ExpireIsCancelledWhenUpdated() { - var remover = _source.ExpireAfter(p => TimeSpan.FromMilliseconds(100), _scheduler).Subscribe(); + var remover = _source.ExpireAfter(p => TimeSpan.FromMilliseconds(100), scheduler: _scheduler).Subscribe(); _source.Edit( updater => @@ -106,7 +106,7 @@ public void ExpireIsCancelledWhenUpdated() [Fact] public void ItemAddedIsExpired() { - var remover = _source.ExpireAfter(p => TimeSpan.FromMilliseconds(100), _scheduler).Subscribe(); + var remover = _source.ExpireAfter(p => TimeSpan.FromMilliseconds(100), scheduler: _scheduler).Subscribe(); _source.AddOrUpdate(new Person("Name1", 10)); diff --git a/src/DynamicData.Tests/Cache/TimeExpiryFixture.cs b/src/DynamicData.Tests/Cache/TimeExpiryFixture.cs index 6651deb10..3fb7d6c84 100644 --- a/src/DynamicData.Tests/Cache/TimeExpiryFixture.cs +++ b/src/DynamicData.Tests/Cache/TimeExpiryFixture.cs @@ -27,7 +27,7 @@ public TimeExpiryFixture() _cache = new SourceCache(p => p.Key); _results = new ChangeSetAggregator(_cache.Connect()); - _remover = _cache.ExpireAfter(p => TimeSpan.FromMilliseconds(100), _scheduler).Subscribe(); + _remover = _cache.ExpireAfter(p => TimeSpan.FromMilliseconds(100), scheduler: _scheduler).Subscribe(); } [Fact] @@ -52,7 +52,7 @@ public void AutoRemove() var items = Enumerable.Range(1, size).Select(i => new Person($"Name{i}", i)).ToArray(); _cache.AddOrUpdate(items); - var xxx = _cache.ExpireAfter(RemoveFunc, _scheduler).Subscribe(); + var xxx = _cache.ExpireAfter(RemoveFunc, scheduler: _scheduler).Subscribe(); _scheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks); _scheduler.AdvanceBy(TimeSpan.FromSeconds(5).Ticks); diff --git a/src/DynamicData/Cache/ObservableCacheEx.cs b/src/DynamicData/Cache/ObservableCacheEx.cs index 06676ef97..7bd76f3de 100644 --- a/src/DynamicData/Cache/ObservableCacheEx.cs +++ b/src/DynamicData/Cache/ObservableCacheEx.cs @@ -1187,6 +1187,22 @@ public static IObservable> EditDiff(thi return new EditDiffChangeSetOptional(source, keySelector, equalityComparer).Run(); } + /// + /// Ensures there are no duplicated keys in the observable changeset. + /// + /// The source change set. + /// The type of the object. + /// The type of the key. + /// A changeset which guarantees a key is only present at most once in the changeset. + public static IObservable> EnsureUniqueKeys(this IObservable> source) + where TObject : notnull + where TKey : notnull + { + source.ThrowArgumentNullExceptionIfNull(nameof(source)); + + return new UniquenessEnforcer(source).Run(); + } + /// /// Signal observers to re-evaluate the specified item. /// @@ -1429,58 +1445,6 @@ public static IObservable> ExpireAfter( return new TimeExpirer(source, timeSelector, pollingInterval, scheduler).ExpireAfter(); } - /// - /// Automatically removes items from the cache after the time specified by - /// the time selector elapses. - /// - /// The type of the object. - /// The type of the key. - /// The cache. - /// The time selector. Return null if the item should never be removed. - /// The scheduler to perform the work on. - /// An observable of enumerable of the key values which has been removed. - /// source - /// or - /// timeSelector. - public static IObservable>> ExpireAfter(this ISourceCache source, Func timeSelector, IScheduler? scheduler = null) - where TObject : notnull - where TKey : notnull => source.ExpireAfter(timeSelector, null, scheduler); - - /// - /// Automatically removes items from the cache after the time specified by - /// the time selector elapses. - /// - /// The type of the object. - /// The type of the key. - /// The cache. - /// The time selector. Return null if the item should never be removed. - /// A polling interval. Since multiple timer subscriptions can be expensive, - /// it may be worth setting the interval . - /// - /// An observable of enumerable of the key values which has been removed. - /// source - /// or - /// timeSelector. - public static IObservable>> ExpireAfter(this ISourceCache source, Func timeSelector, TimeSpan? interval = null) - where TObject : notnull - where TKey : notnull => ExpireAfter(source, timeSelector, interval, Scheduler.Default); - - /// - /// Ensures there are no duplicated keys in the observable changeset. - /// - /// The source change set. - /// The type of the object. - /// The type of the key. - /// A changeset which guarantees a key is only present at most once in the changeset. - public static IObservable> EnsureUniqueKeys(this IObservable> source) - where TObject : notnull - where TKey : notnull - { - source.ThrowArgumentNullExceptionIfNull(nameof(source)); - - return new UniquenessEnforcer(source).Run(); - } - /// /// Automatically removes items from the cache after the time specified by /// the time selector elapses. @@ -1497,7 +1461,11 @@ public static IObservable> EnsureUniqueKeyssource /// or /// timeSelector. - public static IObservable>> ExpireAfter(this ISourceCache source, Func timeSelector, TimeSpan? pollingInterval, IScheduler? scheduler) + public static IObservable>> ExpireAfter( + this ISourceCache source, + Func timeSelector, + TimeSpan? pollingInterval = null, + IScheduler? scheduler = null) where TObject : notnull where TKey : notnull {