ZiggyCreatures / FusionCache

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

Fix OnMiss not firing in all cases in Distributed Cache #211

Closed ConMur closed 3 months ago

ConMur commented 4 months ago

In the current implementation of DistributedCacheAccessor (both Sync and Async) the only time _events.OnMiss fires is when

  1. The de-serialized entry is null
  2. The de-serialization fails

The bug is in case 1. The code currently checks that the value returned from the IDistributedCache is non null and returns early if it is null. This means we never start de-serialization and therefore never call _events.OnMiss. This leads to inaccurate distributed cache miss counters.

To fix this I added _events.OnMiss to the if block that checks the result from the IDistributedCache. This will cause the OnMiss event to also be triggered in the case of an exception from the IDistributedCache. If this behavior is not desired I can update the code to only fire the event when the result from the IDistributedCache is null.

jodydonetti commented 4 months ago

Hi @ConMur and thanks for using FusionCache!

Sorry for the delay but I was at the MVP Global Summit and was not able to look into this. You seem to have a point: I'll look into it asap and will let you know.

Thanks!

jodydonetti commented 3 months ago

I'm looking into this, will update soon.