Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Group 2] Enable nullable annotations for Microsoft.Extensions.Caching.Abstractions #64018

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public DistributedCacheEntryOptions() { }
}
public static partial class DistributedCacheExtensions
{
public static string GetString(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key) { throw null; }
public static System.Threading.Tasks.Task<string> GetStringAsync(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) { throw null; }
public static string? GetString(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key) { throw null; }
public static System.Threading.Tasks.Task<string?> GetStringAsync(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) { throw null; }
public static void Set(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, byte[] value) { }
public static System.Threading.Tasks.Task SetAsync(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, byte[] value, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) { throw null; }
public static void SetString(this Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, string key, string value) { }
Expand All @@ -32,8 +32,8 @@ public static void SetString(this Microsoft.Extensions.Caching.Distributed.IDist
}
public partial interface IDistributedCache
{
byte[] Get(string key);
System.Threading.Tasks.Task<byte[]> GetAsync(string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken));
byte[]? Get(string key);
System.Threading.Tasks.Task<byte[]?> GetAsync(string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken));
void Refresh(string key);
System.Threading.Tasks.Task RefreshAsync(string key, System.Threading.CancellationToken token = default(System.Threading.CancellationToken));
void Remove(string key);
Expand All @@ -48,7 +48,7 @@ public static partial class CacheEntryExtensions
{
public static Microsoft.Extensions.Caching.Memory.ICacheEntry AddExpirationToken(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; }
public static Microsoft.Extensions.Caching.Memory.ICacheEntry RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback) { throw null; }
public static Microsoft.Extensions.Caching.Memory.ICacheEntry RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object state) { throw null; }
public static Microsoft.Extensions.Caching.Memory.ICacheEntry RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object? state) { throw null; }
public static Microsoft.Extensions.Caching.Memory.ICacheEntry SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, System.DateTimeOffset absolute) { throw null; }
public static Microsoft.Extensions.Caching.Memory.ICacheEntry SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, System.TimeSpan relative) { throw null; }
public static Microsoft.Extensions.Caching.Memory.ICacheEntry SetOptions(this Microsoft.Extensions.Caching.Memory.ICacheEntry entry, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options) { throw null; }
Expand All @@ -59,16 +59,16 @@ public static partial class CacheEntryExtensions
}
public static partial class CacheExtensions
{
public static object Get(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; }
public static System.Threading.Tasks.Task<TItem> GetOrCreateAsync<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func<Microsoft.Extensions.Caching.Memory.ICacheEntry, System.Threading.Tasks.Task<TItem>> factory) { throw null; }
public static TItem GetOrCreate<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func<Microsoft.Extensions.Caching.Memory.ICacheEntry, TItem> factory) { throw null; }
public static TItem Get<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; }
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value) { throw null; }
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options) { throw null; }
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; }
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, System.DateTimeOffset absoluteExpiration) { throw null; }
public static TItem Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem value, System.TimeSpan absoluteExpirationRelativeToNow) { throw null; }
public static bool TryGetValue<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, out TItem value) { throw null; }
public static object? Get(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; }
public static System.Threading.Tasks.Task<TItem> GetOrCreateAsync<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func<Microsoft.Extensions.Caching.Memory.ICacheEntry, System.Threading.Tasks.Task<TItem?>> factory) { throw null; }
public static TItem? GetOrCreate<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, System.Func<Microsoft.Extensions.Caching.Memory.ICacheEntry, TItem?> factory) { throw null; }
public static TItem? Get<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key) { throw null; }
public static TItem? Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value) { throw null; }
public static TItem? Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions? options) { throw null; }
public static TItem? Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; }
public static TItem? Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, System.DateTimeOffset absoluteExpiration) { throw null; }
public static TItem? Set<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, TItem? value, System.TimeSpan absoluteExpirationRelativeToNow) { throw null; }
public static bool TryGetValue<TItem>(this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, out TItem? value) { throw null; }
}
public enum CacheItemPriority
{
Expand Down Expand Up @@ -96,19 +96,19 @@ public partial interface ICacheEntry : System.IDisposable
Microsoft.Extensions.Caching.Memory.CacheItemPriority Priority { get; set; }
long? Size { get; set; }
System.TimeSpan? SlidingExpiration { get; set; }
object Value { get; set; }
object? Value { get; set; }
}
public partial interface IMemoryCache : System.IDisposable
{
Microsoft.Extensions.Caching.Memory.ICacheEntry CreateEntry(object key);
void Remove(object key);
bool TryGetValue(object key, out object value);
bool TryGetValue(object key, out object? value);
}
public static partial class MemoryCacheEntryExtensions
{
public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions AddExpirationToken(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Primitives.IChangeToken expirationToken) { throw null; }
public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback) { throw null; }
public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object state) { throw null; }
public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions RegisterPostEvictionCallback(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.PostEvictionDelegate callback, object? state) { throw null; }
public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, System.DateTimeOffset absolute) { throw null; }
public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions SetAbsoluteExpiration(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, System.TimeSpan relative) { throw null; }
public static Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions SetPriority(this Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions options, Microsoft.Extensions.Caching.Memory.CacheItemPriority priority) { throw null; }
Expand All @@ -130,9 +130,9 @@ public partial class PostEvictionCallbackRegistration
{
public PostEvictionCallbackRegistration() { }
public Microsoft.Extensions.Caching.Memory.PostEvictionDelegate EvictionCallback { get { throw null; } set { } }
public object State { get { throw null; } set { } }
public object? State { get { throw null; } set { } }
}
public delegate void PostEvictionDelegate(object key, object value, Microsoft.Extensions.Caching.Memory.EvictionReason reason, object state);
public delegate void PostEvictionDelegate(object key, object? value, Microsoft.Extensions.Caching.Memory.EvictionReason reason, object? state);
}
namespace Microsoft.Extensions.Internal
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static ICacheEntry RegisterPostEvictionCallback(
public static ICacheEntry RegisterPostEvictionCallback(
this ICacheEntry entry,
PostEvictionDelegate callback,
object state)
object? state)
{
if (callback == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public static void SetString(this IDistributedCache cache, string key, string va
/// <param name="cache">The cache in which to store the data.</param>
/// <param name="key">The key to get the stored data for.</param>
/// <returns>The string value from the stored cache key.</returns>
public static string GetString(this IDistributedCache cache, string key)
public static string? GetString(this IDistributedCache cache, string key)
{
byte[] data = cache.Get(key);
byte[]? data = cache.Get(key);
if (data == null)
{
return null;
Expand All @@ -150,9 +150,9 @@ public static string GetString(this IDistributedCache cache, string key)
/// <param name="key">The key to get the stored data for.</param>
/// <param name="token">Optional. A <see cref="CancellationToken" /> to cancel the operation.</param>
/// <returns>A task that gets the string value from the stored cache key.</returns>
public static async Task<string> GetStringAsync(this IDistributedCache cache, string key, CancellationToken token = default(CancellationToken))
public static async Task<string?> GetStringAsync(this IDistributedCache cache, string key, CancellationToken token = default(CancellationToken))
{
byte[] data = await cache.GetAsync(key, token).ConfigureAwait(false);
byte[]? data = await cache.GetAsync(key, token).ConfigureAwait(false);
if (data == null)
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface ICacheEntry : IDisposable
/// <summary>
/// Gets or set the value of the cache entry.
/// </summary>
object Value { get; set; }
object? Value { get; set; }

/// <summary>
/// Gets or sets an absolute expiration date for the cache entry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public interface IDistributedCache
/// </summary>
/// <param name="key">A string identifying the requested value.</param>
/// <returns>The located value or null.</returns>
byte[] Get(string key);
byte[]? Get(string key);

/// <summary>
/// Gets a value with the given key.
/// </summary>
/// <param name="key">A string identifying the requested value.</param>
/// <param name="token">Optional. The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation, containing the located value or null.</returns>
Task<byte[]> GetAsync(string key, CancellationToken token = default(CancellationToken));
Task<byte[]?> GetAsync(string key, CancellationToken token = default(CancellationToken));

/// <summary>
/// Sets a value with the given key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IMemoryCache : IDisposable
/// <param name="key">An object identifying the requested entry.</param>
/// <param name="value">The located value or null.</param>
/// <returns>True if the key was found.</returns>
bool TryGetValue(object key, out object value);
bool TryGetValue(object key, out object? value);

/// <summary>
/// Create or overwrite an entry in the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static MemoryCacheEntryOptions RegisterPostEvictionCallback(
public static MemoryCacheEntryOptions RegisterPostEvictionCallback(
this MemoryCacheEntryOptions options,
PostEvictionDelegate callback,
object state)
object? state)
{
if (callback == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace Microsoft.Extensions.Caching.Memory
{
public static class CacheExtensions
{
public static object Get(this IMemoryCache cache, object key)
public static object? Get(this IMemoryCache cache, object key)
{
cache.TryGetValue(key, out object value);
cache.TryGetValue(key, out object? value);
return value;
}

public static TItem Get<TItem>(this IMemoryCache cache, object key)
public static TItem? Get<TItem>(this IMemoryCache cache, object key)
{
return (TItem)(cache.Get(key) ?? default(TItem));
return (TItem?)(cache.Get(key) ?? default(TItem));
}

public static bool TryGetValue<TItem>(this IMemoryCache cache, object key, out TItem value)
public static bool TryGetValue<TItem>(this IMemoryCache cache, object key, out TItem? value)
{
if (cache.TryGetValue(key, out object result))
if (cache.TryGetValue(key, out object? result))
{
if (result == null)
{
Expand All @@ -41,15 +41,15 @@ public static bool TryGetValue<TItem>(this IMemoryCache cache, object key, out T
return false;
}

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value)
public static TItem? Set<TItem>(this IMemoryCache cache, object key, TItem? value)
{
using ICacheEntry entry = cache.CreateEntry(key);
entry.Value = value;

return value;
}

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration)
public static TItem? Set<TItem>(this IMemoryCache cache, object key, TItem? value, DateTimeOffset absoluteExpiration)
{
using ICacheEntry entry = cache.CreateEntry(key);
entry.AbsoluteExpiration = absoluteExpiration;
Expand All @@ -58,7 +58,7 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,
return value;
}

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, TimeSpan absoluteExpirationRelativeToNow)
public static TItem? Set<TItem>(this IMemoryCache cache, object key, TItem? value, TimeSpan absoluteExpirationRelativeToNow)
{
using ICacheEntry entry = cache.CreateEntry(key);
entry.AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow;
Expand All @@ -67,7 +67,7 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,
return value;
}

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, IChangeToken expirationToken)
public static TItem? Set<TItem>(this IMemoryCache cache, object key, TItem? value, IChangeToken expirationToken)
{
using ICacheEntry entry = cache.CreateEntry(key);
entry.AddExpirationToken(expirationToken);
Expand All @@ -76,7 +76,7 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,
return value;
}

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, MemoryCacheEntryOptions options)
public static TItem? Set<TItem>(this IMemoryCache cache, object key, TItem? value, MemoryCacheEntryOptions? options)
{
using ICacheEntry entry = cache.CreateEntry(key);
if (options != null)
Expand All @@ -89,30 +89,30 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,
return value;
}

public static TItem GetOrCreate<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, TItem> factory)
public static TItem? GetOrCreate<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, TItem?> factory)
{
if (!cache.TryGetValue(key, out object result))
if (!cache.TryGetValue(key, out object? result))
{
using ICacheEntry entry = cache.CreateEntry(key);

result = factory(entry);
entry.Value = result;
}

return (TItem)result;
return (TItem?)result;
}

public static async Task<TItem> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem>> factory)
public static async Task<TItem?> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem?>> factory)
{
if (!cache.TryGetValue(key, out object result))
if (!cache.TryGetValue(key, out object? result))
{
using ICacheEntry entry = cache.CreateEntry(key);

result = await factory(entry).ConfigureAwait(false);
entry.Value = result;
}

return (TItem)result;
return (TItem?)result;
}
}
}
Loading