Skip to content

Commit

Permalink
Deprecate ICacheMethod.FlushAsync in favor of ClearAsync #31
Browse files Browse the repository at this point in the history
  • Loading branch information
Archomeda committed Feb 20, 2020
1 parent 91a270b commit 345d1dd
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gw2Sharp.Tests/WebApi/Caching/BaseCacheMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task FlushTest()
await this.cacheMethod.SetAsync(cacheItem);
Assert.Equal(cacheItem, await this.cacheMethod.TryGetAsync<int>(cacheItem.Category, cacheItem.Id));

await this.cacheMethod.FlushAsync();
await this.cacheMethod.ClearAsync();
Assert.Null(await this.cacheMethod.TryGetAsync<int>(cacheItem.Category, cacheItem.Id));
}

Expand Down
2 changes: 1 addition & 1 deletion Gw2Sharp.Tests/WebApi/Caching/NullCacheMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task FlushTest()
await this.cacheMethod.SetAsync(cacheItem);
Assert.Null(await this.cacheMethod.TryGetAsync<int>(cacheItem.Category, cacheItem.Id));

await this.cacheMethod.FlushAsync();
await this.cacheMethod.ClearAsync();
Assert.Null(await this.cacheMethod.TryGetAsync<int>(cacheItem.Category, cacheItem.Id));
}

Expand Down
2 changes: 1 addition & 1 deletion Gw2Sharp/WebApi/Caching/ArchiveCacheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private async Task<IDictionary<object, CacheItem<T>>> GetManyInternalAsync<T>(st
}

/// <inheritdoc />
public override async Task FlushAsync()
public override async Task ClearAsync()
{
lock (this.operationLock)
{
Expand Down
7 changes: 6 additions & 1 deletion Gw2Sharp/WebApi/Caching/BaseCacheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ private async Task<IList<CacheItem<T>>> GetOrUpdateManyInternalAsync<T>(
}

/// <inheritdoc />
public abstract Task FlushAsync();
[Obsolete("Use ClearAsync instead. Will be removed starting with version 0.9.0")]
public Task FlushAsync() =>
this.ClearAsync();

/// <inheritdoc />
public abstract Task ClearAsync();

/// <summary>
/// Disposes the object.
Expand Down
23 changes: 15 additions & 8 deletions Gw2Sharp/WebApi/Caching/ICacheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public interface ICacheMethod : IDisposable
/// <param name="category">The cache category.</param>
/// <param name="id">The id.</param>
/// <returns>The task for this operation with a returned cached item if it exists and is not expired; <c>null</c> otherwise.</returns>
Task<CacheItem<T>?> TryGetAsync<T>(string category, object id) ;
Task<CacheItem<T>?> TryGetAsync<T>(string category, object id);

/// <summary>
/// Sets a cached item.
/// </summary>
/// <typeparam name="T">The cache type.</typeparam>
/// <param name="item">The item to cache.</param>
/// <returns>The task for this operation.</returns>
Task SetAsync<T>(CacheItem<T> item) ;
Task SetAsync<T>(CacheItem<T> item);

/// <summary>
/// Sets a cached item.
Expand All @@ -35,7 +35,7 @@ public interface ICacheMethod : IDisposable
/// <param name="item">The item to cache.</param>
/// <param name="expiryTime">The expiry time.</param>
/// <returns>The task for this operation.</returns>
Task SetAsync<T>(string category, object id, T item, DateTimeOffset expiryTime) ;
Task SetAsync<T>(string category, object id, T item, DateTimeOffset expiryTime);

/// <summary>
/// Gets many cached items of a given type at once.
Expand All @@ -47,15 +47,15 @@ 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.
/// </returns>
Task<IDictionary<object, CacheItem<T>>> GetManyAsync<T>(string category, IEnumerable<object> ids) ;
Task<IDictionary<object, CacheItem<T>>> GetManyAsync<T>(string category, IEnumerable<object> ids);

/// <summary>
/// Sets many cached items of a given type at once.
/// </summary>
/// <typeparam name="T">The cache type.</typeparam>
/// <param name="items">The items.</param>
/// <returns>The task for this operation.</returns>
Task SetManyAsync<T>(IEnumerable<CacheItem<T>> items) ;
Task SetManyAsync<T>(IEnumerable<CacheItem<T>> items);

/// <summary>
/// Gets a cached item if it exists. If it doesn't exist, it calls <paramref name="updateFunc"/> to provide an updated value,
Expand All @@ -67,7 +67,7 @@ public interface ICacheMethod : IDisposable
/// <param name="expiryTime">The expiry date.</param>
/// <param name="updateFunc">The method that is called when no cache has been found.</param>
/// <returns>The item.</returns>
Task<CacheItem<T>> GetOrUpdateAsync<T>(string category, object id, DateTimeOffset expiryTime, Func<Task<T>> updateFunc) ;
Task<CacheItem<T>> GetOrUpdateAsync<T>(string category, object id, DateTimeOffset expiryTime, Func<Task<T>> updateFunc);

/// <summary>
/// Gets a cached item if it exists. If it doesn't exist, it calls <paramref name="updateFunc"/> to provide an updated value and its expiry date,
Expand All @@ -78,7 +78,7 @@ public interface ICacheMethod : IDisposable
/// <param name="id">The cache id.</param>
/// <param name="updateFunc">The method that is called when no cache has been found.</param>
/// <returns>The item.</returns>
Task<CacheItem<T>> GetOrUpdateAsync<T>(string category, object id, Func<Task<(T, DateTimeOffset)>> updateFunc) ;
Task<CacheItem<T>> GetOrUpdateAsync<T>(string category, object id, Func<Task<(T, DateTimeOffset)>> updateFunc);

/// <summary>
/// Gets cached items if they exist. If one or more don't exist, <paramref name="updateFunc"/> will be called to provide updated values and their expiry date,
Expand Down Expand Up @@ -111,9 +111,16 @@ Task<IList<CacheItem<T>>> GetOrUpdateManyAsync<T>(
Func<IList<object>, Task<IDictionary<object, T>>> updateFunc);

/// <summary>
/// Flushes the cache, a.k.a. empties the cache.
/// Clears the cache, a.k.a. empties the cache.
/// </summary>
/// <returns>The task for this operation.</returns>
[Obsolete("Use ClearAsync instead. Will be removed starting with version 0.9.0")]
Task FlushAsync();

/// <summary>
/// Clears the cache, a.k.a. empties the cache.
/// </summary>
/// <returns>The task for this operation.</returns>
Task ClearAsync();
}
}
2 changes: 1 addition & 1 deletion Gw2Sharp/WebApi/Caching/MemoryCacheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private async Task<IDictionary<object, CacheItem<T>>> GetManyInternalAsync<T>(st
}

/// <inheritdoc />
public override async Task FlushAsync() =>
public override async Task ClearAsync() =>
this.cachedItems.Clear();

private bool isDisposed = false; // To detect redundant calls
Expand Down
2 changes: 1 addition & 1 deletion Gw2Sharp/WebApi/Caching/NullCacheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override async Task SetManyAsync<T>(IEnumerable<CacheItem<T>> items)
}

/// <inheritdoc />
public override async Task FlushAsync()
public override async Task ClearAsync()
{
// Nothing to do
}
Expand Down

0 comments on commit 345d1dd

Please sign in to comment.