I have the following implementation of MemoryCache
:
public Task<News[]> GetCandidateNewsAsync(string candidate)
{
return _cache.GetOrCreateAsync(candidate, async factory =>// _cache é um IMemoryCache
{
var candidateUri = _candidateUris[candidate];
if (string.IsNullOrEmpty(candidateUri))
return null; //retorno nulo aqui (erro)
var candidateNews = await _candidateNewsClient.GetCandidateNewsAsync(1, candidateUri);
return candidateNews?.News;
});
}
I ran a code analyzer on top of my project and it reported the following:
Do not return this method, instead return 'Task.FromResult (null)', 'Task.CompletedTask' or 'Task.Delay (0)'
I just did not get it right, what's the problem of returning null on this occasion? What's the point of returning a delay of 0ms as he recommends?