MichaCo / CacheManager

CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
http://cachemanager.michaco.net
Apache License 2.0
2.33k stars 458 forks source link

ASP.NET Core 3 Support #287

Closed snowchenlei closed 4 years ago

snowchenlei commented 4 years ago

ASP.NET Core 3 Support

MichaCo commented 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

snowchenlei commented 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

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?

MichaCo commented 4 years ago

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')
snowchenlei commented 4 years ago

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 image I Hope This Is Ok Not Throw ArgumentNullException Because Generic types Is Nullable types。 Or I use it incorrectly?

MichaCo commented 4 years ago

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

snowchenlei commented 4 years ago

Ok, I See. Thank you!