dotnet core mvc memoryCache.Get returns async response?

166 views Asked by At

I am using .net core MVC 2.1. I amtrying to use ImemoryCache Get method

enter image description here

I looked at the Get method response and seems its async. It returns object and does not allow me to put obj.Result also.

When I see the documentation No where in the sample the response is async.

Why am I getting this issue?

1

There are 1 answers

0
Nguyen Thanh On

Because the data in memory is Task<List<ApplicationConfigurationKeyPairModel>> but according to your code, you want to get it as IList<ApplicationConfigurationKeyPairModel> without convert from Task value to normal value.

So if you want to get it normally without error, you shall do it like this:

var allSettings = _memoryCache.TryGetValue(UtilityHelper.APPLICATION_SETTINGS_ALL, out var value);

Then you can check what type of value is and convert it to list by using value.Result.