From 345d1dd1b756e10d6a262558a76996ac807ce85c Mon Sep 17 00:00:00 2001 From: Archomeda Date: Thu, 20 Feb 2020 02:02:55 +0100 Subject: [PATCH] Deprecate ICacheMethod.FlushAsync in favor of ClearAsync #31 --- .../WebApi/Caching/BaseCacheMethodTests.cs | 2 +- .../WebApi/Caching/NullCacheMethodTests.cs | 2 +- Gw2Sharp/WebApi/Caching/ArchiveCacheMethod.cs | 2 +- Gw2Sharp/WebApi/Caching/BaseCacheMethod.cs | 7 +++++- Gw2Sharp/WebApi/Caching/ICacheMethod.cs | 23 ++++++++++++------- Gw2Sharp/WebApi/Caching/MemoryCacheMethod.cs | 2 +- Gw2Sharp/WebApi/Caching/NullCacheMethod.cs | 2 +- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Gw2Sharp.Tests/WebApi/Caching/BaseCacheMethodTests.cs b/Gw2Sharp.Tests/WebApi/Caching/BaseCacheMethodTests.cs index 26f3158ba..8bc78a3aa 100644 --- a/Gw2Sharp.Tests/WebApi/Caching/BaseCacheMethodTests.cs +++ b/Gw2Sharp.Tests/WebApi/Caching/BaseCacheMethodTests.cs @@ -26,7 +26,7 @@ public async Task FlushTest() await this.cacheMethod.SetAsync(cacheItem); Assert.Equal(cacheItem, await this.cacheMethod.TryGetAsync(cacheItem.Category, cacheItem.Id)); - await this.cacheMethod.FlushAsync(); + await this.cacheMethod.ClearAsync(); Assert.Null(await this.cacheMethod.TryGetAsync(cacheItem.Category, cacheItem.Id)); } diff --git a/Gw2Sharp.Tests/WebApi/Caching/NullCacheMethodTests.cs b/Gw2Sharp.Tests/WebApi/Caching/NullCacheMethodTests.cs index a17f61aeb..04637ae15 100644 --- a/Gw2Sharp.Tests/WebApi/Caching/NullCacheMethodTests.cs +++ b/Gw2Sharp.Tests/WebApi/Caching/NullCacheMethodTests.cs @@ -24,7 +24,7 @@ public async Task FlushTest() await this.cacheMethod.SetAsync(cacheItem); Assert.Null(await this.cacheMethod.TryGetAsync(cacheItem.Category, cacheItem.Id)); - await this.cacheMethod.FlushAsync(); + await this.cacheMethod.ClearAsync(); Assert.Null(await this.cacheMethod.TryGetAsync(cacheItem.Category, cacheItem.Id)); } diff --git a/Gw2Sharp/WebApi/Caching/ArchiveCacheMethod.cs b/Gw2Sharp/WebApi/Caching/ArchiveCacheMethod.cs index a63c0f36a..6237af8d6 100644 --- a/Gw2Sharp/WebApi/Caching/ArchiveCacheMethod.cs +++ b/Gw2Sharp/WebApi/Caching/ArchiveCacheMethod.cs @@ -211,7 +211,7 @@ private async Task>> GetManyInternalAsync(st } /// - public override async Task FlushAsync() + public override async Task ClearAsync() { lock (this.operationLock) { diff --git a/Gw2Sharp/WebApi/Caching/BaseCacheMethod.cs b/Gw2Sharp/WebApi/Caching/BaseCacheMethod.cs index 4082b3448..cccae8f9a 100644 --- a/Gw2Sharp/WebApi/Caching/BaseCacheMethod.cs +++ b/Gw2Sharp/WebApi/Caching/BaseCacheMethod.cs @@ -152,7 +152,12 @@ private async Task>> GetOrUpdateManyInternalAsync( } /// - public abstract Task FlushAsync(); + [Obsolete("Use ClearAsync instead. Will be removed starting with version 0.9.0")] + public Task FlushAsync() => + this.ClearAsync(); + + /// + public abstract Task ClearAsync(); /// /// Disposes the object. diff --git a/Gw2Sharp/WebApi/Caching/ICacheMethod.cs b/Gw2Sharp/WebApi/Caching/ICacheMethod.cs index a98f838f7..29a8e881e 100644 --- a/Gw2Sharp/WebApi/Caching/ICacheMethod.cs +++ b/Gw2Sharp/WebApi/Caching/ICacheMethod.cs @@ -16,7 +16,7 @@ public interface ICacheMethod : IDisposable /// The cache category. /// The id. /// The task for this operation with a returned cached item if it exists and is not expired; null otherwise. - Task?> TryGetAsync(string category, object id) ; + Task?> TryGetAsync(string category, object id); /// /// Sets a cached item. @@ -24,7 +24,7 @@ public interface ICacheMethod : IDisposable /// The cache type. /// The item to cache. /// The task for this operation. - Task SetAsync(CacheItem item) ; + Task SetAsync(CacheItem item); /// /// Sets a cached item. @@ -35,7 +35,7 @@ public interface ICacheMethod : IDisposable /// The item to cache. /// The expiry time. /// The task for this operation. - Task SetAsync(string category, object id, T item, DateTimeOffset expiryTime) ; + Task SetAsync(string category, object id, T item, DateTimeOffset expiryTime); /// /// Gets many cached items of a given type at once. @@ -47,7 +47,7 @@ public interface ICacheMethod : IDisposable /// The task for this operation with the cached items if they exist and have not expired. /// Only items that exist are included in the returned dictionary. /// - Task>> GetManyAsync(string category, IEnumerable ids) ; + Task>> GetManyAsync(string category, IEnumerable ids); /// /// Sets many cached items of a given type at once. @@ -55,7 +55,7 @@ public interface ICacheMethod : IDisposable /// The cache type. /// The items. /// The task for this operation. - Task SetManyAsync(IEnumerable> items) ; + Task SetManyAsync(IEnumerable> items); /// /// Gets a cached item if it exists. If it doesn't exist, it calls to provide an updated value, @@ -67,7 +67,7 @@ public interface ICacheMethod : IDisposable /// The expiry date. /// The method that is called when no cache has been found. /// The item. - Task> GetOrUpdateAsync(string category, object id, DateTimeOffset expiryTime, Func> updateFunc) ; + Task> GetOrUpdateAsync(string category, object id, DateTimeOffset expiryTime, Func> updateFunc); /// /// Gets a cached item if it exists. If it doesn't exist, it calls to provide an updated value and its expiry date, @@ -78,7 +78,7 @@ public interface ICacheMethod : IDisposable /// The cache id. /// The method that is called when no cache has been found. /// The item. - Task> GetOrUpdateAsync(string category, object id, Func> updateFunc) ; + Task> GetOrUpdateAsync(string category, object id, Func> updateFunc); /// /// Gets cached items if they exist. If one or more don't exist, will be called to provide updated values and their expiry date, @@ -111,9 +111,16 @@ Task>> GetOrUpdateManyAsync( Func, Task>> updateFunc); /// - /// Flushes the cache, a.k.a. empties the cache. + /// Clears the cache, a.k.a. empties the cache. /// /// The task for this operation. + [Obsolete("Use ClearAsync instead. Will be removed starting with version 0.9.0")] Task FlushAsync(); + + /// + /// Clears the cache, a.k.a. empties the cache. + /// + /// The task for this operation. + Task ClearAsync(); } } diff --git a/Gw2Sharp/WebApi/Caching/MemoryCacheMethod.cs b/Gw2Sharp/WebApi/Caching/MemoryCacheMethod.cs index 3a1d341bc..7975147a8 100644 --- a/Gw2Sharp/WebApi/Caching/MemoryCacheMethod.cs +++ b/Gw2Sharp/WebApi/Caching/MemoryCacheMethod.cs @@ -123,7 +123,7 @@ private async Task>> GetManyInternalAsync(st } /// - public override async Task FlushAsync() => + public override async Task ClearAsync() => this.cachedItems.Clear(); private bool isDisposed = false; // To detect redundant calls diff --git a/Gw2Sharp/WebApi/Caching/NullCacheMethod.cs b/Gw2Sharp/WebApi/Caching/NullCacheMethod.cs index 4546dc23c..26eef602d 100644 --- a/Gw2Sharp/WebApi/Caching/NullCacheMethod.cs +++ b/Gw2Sharp/WebApi/Caching/NullCacheMethod.cs @@ -40,7 +40,7 @@ public override async Task SetManyAsync(IEnumerable> items) } /// - public override async Task FlushAsync() + public override async Task ClearAsync() { // Nothing to do }