-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Update IDistributedCache to account for nullability #52148
Comments
Tagging subscribers to this area: @eerhardt, @maryamariyan, @michaelgsharp Issue DetailsBackground and MotivationThe /// <returns>The located value or null.</returns> I noticed this when we were working on adding community contributed APIs, see: dotnet/aspnetcore#32266 (comment). The request here is to update the API in the Proposed APInamespace Microsoft.Extensions.Caching.Distributed
{
public interface IDistributedCache
{
- byte[] Get(string key);
+ byte[]? Get(string key);
- Task<byte[]> GetAsync(string key, CancellationToken token = default(CancellationToken));
+ Task<byte[]?> GetAsync(string key, CancellationToken token = default(CancellationToken));
} Usage ExamplesThe return type will be update: - byte[] data = cache.Get(key);
+ byte[]? data = cache.Get(key); Alternative DesignsThe alternative is to keep the current API. This presents a difficulty when adding nullability checks in implementations of RisksImplementations of the
|
FYI @ericstj @maryamariyan, it seems like nullability is not enabled for |
See #43605. Almost none of the Microsoft.Extensions.* libraries have nullability enabled. |
Is there an estimate of which preview when Caching.Abstractions will be annotated? We can't enable nullability in our package until it's enabled here first. |
FYI, we don't need all of Caching.Abstractions to be updated with nullability enabled. To unblock us, we just need to make the tactical API changes I proposed. |
cc @jeffhandley |
For Caching.Abstractions, looks like it depends on primitives. So it would be only a matter of enabling nullables for these two libraries |
It is blocking us from enabling nullability in Caching.SqlServer and Caching.StackExchangeRedis as part of dotnet/aspnetcore#5680. |
What's the nullable goal for ASP.NET in 6.0? Are you planning to enable it for all apps? You'll need more than just these assemblies annotated. Aren't there other assemblies that ship in the ASP.NET ref-pack which aren't annotated yet? |
We've reached feature complete for .NET 6. Moving to 7. |
Looking again at #43605, all dependencies to |
Background and Motivation
The
Get
andGetAsync
methods of theIDistributedCache
interface do not match the intended nullability in terms of return type. As per the API documentation:/// <returns>The located value or null.</returns>
I noticed this when we were working on adding community contributed APIs, see: dotnet/aspnetcore#32266 (comment).
The request here is to update the API in the
IDistributedCache
interface.Proposed API
Usage Examples
The return type will be update:
Alternative Designs
The alternative is to keep the current API. This presents a difficulty when adding nullability checks in implementations of
IDistributedCache
see dotnet/aspnetcore#32266.Risks
Implementations of the
IDistributedCache
interface will need to be updated to account for the nullability changes proposed here.The text was updated successfully, but these errors were encountered: