Skip to content

Commit

Permalink
remove unnecessary nullables
Browse files Browse the repository at this point in the history
  • Loading branch information
mkozhevnikov committed Oct 3, 2022
1 parent fe104b0 commit 22ceae9
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/Common/Cache/DistributedCacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ public static class DistributedCache
{
private static readonly TimeSpan defaultExpiration = TimeSpan.FromMinutes(1);

public static async ValueTask<T?> GetOrSetAsync<T>(
#region GetOrSet

public static async ValueTask<T> GetOrSetAsync<T>(
this IDistributedCache cache,
string key,
T? value,
T value,
TimeSpan? expiresIn,
JsonSerializerOptions? jsonSerializerOptions = null,
CancellationToken token = default) =>
await cache.GetOrSetAsync(key, () => Task.FromResult(value), expiresIn, jsonSerializerOptions, token);

public static async ValueTask<T?> GetOrSetAsync<T>(
public static async Task<T> GetOrSetAsync<T>(
this IDistributedCache cache,
string key,
Func<Task<T?>> valueFactory,
Func<Task<T>> valueFactory,
TimeSpan? expiresIn,
JsonSerializerOptions? jsonSerializerOptions = null,
CancellationToken token = default)
Expand All @@ -31,10 +33,10 @@ public static class DistributedCache
return await cache.GetOrSetAsync(key, valueFactory, options, jsonSerializerOptions, token);
}

public static async ValueTask<T?> GetOrSetAsync<T>(
public static async Task<T> GetOrSetAsync<T>(
this IDistributedCache cache,
string key,
Func<Task<T?>> valueFactory,
Func<Task<T>> valueFactory,
DistributedCacheEntryOptions? options = null,
JsonSerializerOptions? jsonSerializerOptions = null,
CancellationToken token = default)
Expand All @@ -49,13 +51,17 @@ public static class DistributedCache
return value;
}

public static async ValueTask<T?> GetAsJsonAsync<T>(
#endregion

#region GetAsJson

public static async Task<T?> GetAsJsonAsync<T>(
this IDistributedCache cache,
string key,
CancellationToken token = default) =>
await cache.GetAsJsonAsync<T>(key, null, token);

public static async ValueTask<T?> GetAsJsonAsync<T>(
public static async Task<T?> GetAsJsonAsync<T>(
this IDistributedCache cache,
string key,
JsonSerializerOptions? jsonSerializerOptions,
Expand All @@ -66,7 +72,11 @@ public static class DistributedCache
return bytes == null ? default : Deserialize<T>(bytes, jsonSerializerOptions);
}

public static async ValueTask SetAsJsonAsync<T>(
#endregion

#region SetAsJson

public static async Task SetAsJsonAsync<T>(
this IDistributedCache cache,
string key,
T? value,
Expand All @@ -81,7 +91,7 @@ public static class DistributedCache
await cache.SetAsJsonAsync(key, value, options, null, token);
}

public static async ValueTask SetAsJsonAsync<T>(
public static async Task SetAsJsonAsync<T>(
this IDistributedCache cache,
string key,
T? value,
Expand All @@ -98,7 +108,9 @@ public static class DistributedCache
await cache.SetAsync(key, bytes, options, token);
}

public static async ValueTask<bool> ExistsAsync(
#endregion

public static async Task<bool> ExistsAsync(
this IDistributedCache cache,
string key,
CancellationToken token = default) =>
Expand Down

0 comments on commit 22ceae9

Please sign in to comment.