ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.9k stars 97 forks source link

use some null propagation #223

Closed SimonCropp closed 7 months ago

jodydonetti commented 7 months ago

Hi @SimonCropp thanks for all your contributions in a row!

For this one though, I'm not that positive, let me explain.

I use that same pattern a lot, for both mca (MemoryCacheAccessor), dca (DistributedCacheAccessor) and bpa (BackplaneAccessor), and I like that the same code pattern is used for all of them and all is uniform.

And I cannot use ?. because it cannot be used with multiple lines, and the alternative is that I would have to repeat ?. for every line.

For example with dca I commonly have multi-lines code, like this:

if (dca is not null)
{
    var dcaSuccess = false;
    try
    {
        if (dca.IsCurrentlyUsable(operationId, key))
        {
            dcaSuccess = await distributedCacheAction(dca, isBackground, ct1).ConfigureAwait(false);
        }
    // ...

Same thing for bpa:

if (bpa is not null)
{
    var bpaSuccess = false;
    try
    {
        if (bpa.IsCurrentlyUsable(operationId, key))
        {
            bpaSuccess = await backplaneAction(bpa, isBackplaneBackground, ct2).ConfigureAwait(false);
        }
    }
    // ...

So I think I prefer to keep the codebase as uniform as possible.

Also in this case there are no perf gains, since the lowered code is identical.

But I'm open to a discussion, what do you think?

SimonCropp commented 7 months ago

fair enough. lets close this one