-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
try get nullable #1015
try get nullable #1015
Conversation
I think it depends on what the original intention of the cache policy is - it currently allows null values, so I would have thought the nullable annotations would therefore continue to allow that, otherwise that's a change in behaviour. Looking at |
@martincostello i made some changes based on your feedback. can u take another look. |
Codecov Report
@@ Coverage Diff @@
## main #1015 +/- ##
==========================================
+ Coverage 71.19% 71.22% +0.03%
==========================================
Files 137 137
Lines 3760 3764 +4
Branches 764 764
==========================================
+ Hits 2677 2681 +4
Misses 872 872
Partials 211 211
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -39,7 +40,7 @@ internal static class AsyncCacheEngine | |||
if (cacheHit) | |||
{ | |||
onCacheGet(context, cacheKey); | |||
return valueFromCache; | |||
return valueFromCache!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method return TResult?
so that this isn't needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think so. if we have a cacheHit then we know valueFromCache is not null. so we can be sure ImplementationAsync will return a not null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we changed things based on my earlier comment to allow you to set null
into the cache, so in that case you'd get a cache hit on a null.
@@ -38,7 +39,7 @@ internal static class CacheEngine | |||
if (cacheHit) | |||
{ | |||
onCacheGet(context, cacheKey); | |||
return valueFromCache; | |||
return valueFromCache!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@martincostello
i put together a minimal example to show how i came to use the NotNull for
TResult
inIAsyncCacheProvider<TResult>
this PR enables nullable for
AsyncGenericCacheProvider.cs
andIAsyncCacheProvider
you will notice we get the warning
so in
since someone could define
AsyncGenericCacheProvider<MyType?>
it meansvalue
could be null inso we could allow null for value through the stack. so
IAsyncCacheProvider
would need to accept null forPutAsync
. Do we want that?if we
notnull
onTCacheFormat
it means people cant pass a nullvalue
toPutAsync
.TBH i think the fix here is to add a
Clear
method that takes a key??thoughts?