From cc5a11482c1c797871635eb393c5f6332534a2ee Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Wed, 22 May 2024 20:13:50 +0100 Subject: [PATCH] We are confidence enough that the data will be saved to the db, so lets change how we update the UI, so instead of wating on the db call to complete, we will just update the UI while the db call is in progress --- Toolkit.Foundation/Cache.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Toolkit.Foundation/Cache.cs b/Toolkit.Foundation/Cache.cs index 1cd3b54..4db2762 100644 --- a/Toolkit.Foundation/Cache.cs +++ b/Toolkit.Foundation/Cache.cs @@ -5,16 +5,13 @@ using System.Reactive.Disposables; namespace Toolkit.Foundation; public class Cache(IDisposer disposer, - IComparer comparer) : + IComparer? comparer = default) : ICache { - private readonly SortedSet cache = new(comparer); + private readonly List cache = []; - public int IndexOf(TValue value) - { - ImmutableSortedSet hashSet = cache.ToImmutableSortedSet(comparer); - return hashSet.IndexOf(value); - } + public int IndexOf(TValue value) => + cache.IndexOf(value); public void Add(TValue value) { @@ -25,12 +22,14 @@ public class Cache(IDisposer disposer, disposer.Add(value, Disposable.Create(() => Remove(value))); cache.Add(value); + cache.Sort(comparer); } public bool TryGetValue(TValue key, out TValue? value) { - if (cache.TryGetValue(key, out value)) + if (cache.FirstOrDefault(x => x is not null && x.Equals(key)) is TValue returningValue) { + value = returningValue; return true; } @@ -47,8 +46,7 @@ public class Cache(IDisposer disposer, public bool Remove(TValue value) => cache.Remove(value); } -public class Cache(IDisposer disposer, - IComparer comparer) : +public class Cache(IComparer comparer) : ICache where TKey : notnull