Closed snowchenlei closed 4 years ago
Is this you trying to report any issues you are having, using CacheManager in your ASP.NET Core 3 projects? If so, could you further explain what kind of problems you see? Or is this just random words?
/closing for now as not being clear what this is about
Is this you trying to report any issues you are having, using CacheManager in your ASP.NET Core 3 projects? If so, could you further explain what kind of problems you see? Or is this just random words?
/closing for now as not being clear what this is about
private readonly ICacheManager<DateTime?> _cache;
_cache.Add("key", null);
I Get error "Value cannot be null. (Parameter 'value')" in .net core 3.0; But in .net core 2.2 that's ok! DateTime? Is Nullable But Why Not Set Null?
But in .net core 2.2 that's ok!
I'm sure that's bogus and not true.
DateTime? Is Nullable But Why Not Set Null?
No idea what you are trying to say, sorry ;)
Anyways, I created a simple console app to test your code snippet, just to be absolutely sure, targeting all different target frameworks:
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
Code:
internal class Program
{
private static void Main(string[] args)
{
var cache = new BaseCacheManager<DateTime?>(new CacheManagerConfiguration().Builder.WithDictionaryHandle().Build());
cache.Add("key", null);
}
}
The expected behavior of CacheManager is to throw an ArgumentNullException
if you try to cache null
.
And running the code against all different framework targets behave exactly the same...
Only difference is the error message which changed in .NET Core, but that has nothing todo with CacheManager...
netcoreapp2.x:
System.ArgumentNullException: Value cannot be null.
Parameter name: value
netcoreapp3.0:
System.ArgumentNullException: Value cannot be null. (Parameter 'value')
Please forgive me if my English is not standard! First Sorry! Second:
MemoryCache mcCache= new MemoryCache(new MemoryCacheOptions());
mcCache.Set<int?>("MCKey", null);
It's Ok!
var cache = new BaseCacheManager<int?>(new CacheManagerConfiguration().Builder.WithDictionaryHandle().Build());
cache.Add("key", null);
This Throw ArgumentNullException!
I found a Null check in the CacheItem I Hope This Is Ok Not Throw ArgumentNullException Because Generic types Is Nullable types。 Or I use it incorrectly?
Your first example is not CacheManager, MemoryCache is the Microsoft.Extensions.Caching.Memory cache I guess? Yes, other caches might support caching nulls.
CacheManager does not allow null as value for a cache key and the fact that you get a ArgumentNullException in your second example is by design
Ok, I See. Thank you!
ASP.NET Core 3 Support