diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 28ebe28..43644b1 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ true - $(NoWarn);1591;1701;1702;1705;VSX1000 + $(NoWarn);1591;1701;1702;1705;VSX1000;IDE0190 AnyCPU $(MSBuildProjectName.Contains('Tests')) embedded diff --git a/src/ReactiveMarbles.CacheDatabase.EncryptedSettings.Tests/SettingsCacheTests.cs b/src/ReactiveMarbles.CacheDatabase.EncryptedSettings.Tests/SettingsCacheTests.cs index 01763d5..eb2742d 100644 --- a/src/ReactiveMarbles.CacheDatabase.EncryptedSettings.Tests/SettingsCacheTests.cs +++ b/src/ReactiveMarbles.CacheDatabase.EncryptedSettings.Tests/SettingsCacheTests.cs @@ -14,7 +14,6 @@ public class SettingsCacheTests /// /// Test1s this instance. /// - /// Name of the override database. [Fact] public async void TestCreateAndInsert() { diff --git a/src/ReactiveMarbles.CacheDatabase.Settings/Core/AppInfo.cs b/src/ReactiveMarbles.CacheDatabase.Settings/Core/AppInfo.cs index 51c9c0b..fc412aa 100644 --- a/src/ReactiveMarbles.CacheDatabase.Settings/Core/AppInfo.cs +++ b/src/ReactiveMarbles.CacheDatabase.Settings/Core/AppInfo.cs @@ -85,10 +85,7 @@ static AppInfo() /// Overrides the settings cache path. /// /// The path. - public static void OverrideSettingsCachePath(string path) - { - SettingsCachePath = path; - } + public static void OverrideSettingsCachePath(string path) => SettingsCachePath = path; /// /// Deletes the settings store. diff --git a/src/ReactiveMarbles.CacheDatabase.Settings/Core/SettingsStorage.cs b/src/ReactiveMarbles.CacheDatabase.Settings/Core/SettingsStorage.cs index 12f668d..f40d68a 100644 --- a/src/ReactiveMarbles.CacheDatabase.Settings/Core/SettingsStorage.cs +++ b/src/ReactiveMarbles.CacheDatabase.Settings/Core/SettingsStorage.cs @@ -83,7 +83,12 @@ public void Dispose() /// /// A task that represents the asynchronous dispose operation. /// - public ValueTask DisposeAsync() => _blobCache.DisposeAsync(); + public ValueTask DisposeAsync() + { + var result = _blobCache.DisposeAsync(); + GC.SuppressFinalize(this); + return result; + } /// /// Gets the value for the specified key, or, if the value doesn't exist, saves the and returns it. diff --git a/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs b/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs index f26cade..c45621a 100644 --- a/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs +++ b/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs @@ -171,43 +171,10 @@ public IObservable Flush(Type type) } var time = DateTimeOffset.UtcNow; - return _initialized - .SelectMany(async _ => - { - try - { - var value = await Connection.GetAsync(key).ConfigureAwait(false); - - if (value is null) - { - throw new KeyNotFoundException($"Key {key} could not be found."); - } - - if (value.TypeName is not null) - { - throw new KeyNotFoundException($"Key {key} is associated with an object."); - } - - if (value.Id is null) - { - throw new KeyNotFoundException($"Key {key} is id is null."); - } - - if (value.ExpiresAt <= time) - { - throw new KeyNotFoundException($"Key {key} has expired."); - } - - return value; - } - catch (Exception) - { - throw new KeyNotFoundException($"Key {key} could not be found."); - } - }) - .Select(x => x.Value) - .Where(x => x is not null) - .Select(x => x!); + return _initialized.SelectMany((_, _, _) => Connection.Table().FirstAsync(x => x.Id != null && x.ExpiresAt > time && x.Id == key)) + .Catch(ex => Observable.Throw(new KeyNotFoundException(ex.Message))) + .Where(x => x?.Value is not null) + .Select(x => x.Value!); } /// diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs b/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs index b4bc839..5263925 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs @@ -1185,6 +1185,25 @@ public async Task VacuumPurgeEntriesThatAreExpired() } } + /// + /// Tests the issue. + /// + /// A representing the asynchronous unit test. + [Fact] + public async Task TestIssueAsync() + { + using (Utility.WithEmptyDirectory(out var path)) + await using (var fixture = CreateBlobCache(path)) + { + var cacheKey = "cacheKey"; + var someObject = new string[] { "someObject" }; + await fixture.InsertObject(cacheKey, someObject.AsEnumerable(), null); + Assert.NotNull(await fixture.GetObject>(cacheKey)); + Assert.NotNull(await fixture.Get(cacheKey, typeof(IEnumerable))); + Assert.NotNull(await fixture.Get(cacheKey)); + } + } + /// /// Gets the we want to do the tests against. ///