ZiggyCreatures / FusionCache

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

First cached entry using GetOrSet should trigger Miss event #49

Closed JoeShook closed 2 years ago

JoeShook commented 2 years ago

The following code will trigger the SET event and I thing that is good and correct. But it does not trigger the Miss event. I think it should trigger the Miss event if it did not previously exist in the cache at anytime. Think about it this way. If you have a cache item in a cache it had to get there because once upon a time it as not in the cache, thus the rational that it should have historicaly been a cache miss. I discovered this while building my OpenTelemetry plugin examples. I am using the GetOrSet now that I have the Adaptive Caching feature in my hands. That is when I realized couldn't find a Miss events in my prometheus (time series) database.

await cache.GetOrSetAsync<int>(
    "foo",
    async (_) =>
    {
        await Task.Delay(1);
        return 123;
    });
jodydonetti commented 2 years ago

Hi @JoeShook , yeah what you've said seems to make sense.

Like said here a "first" GetOrSet call should emit a MISS event followed by a SET event.

Looking at the git history though, I see that I explicitly changed that behavior when introducing the backplane, so I have to think a little bit about it to remember why that was the case.

image

In any case I will end up either changing the behavior or changing the docs, so thanks for spotting it.

Will update.

jodydonetti commented 2 years ago

Hi @JoeShook , I've just made the change on a local copy: will publish it in the next days I hope. Is there something else that you discovered regarding events since you created this issue? Thanks!

JoeShook commented 2 years ago

I checked the Main branch against the Metrics Plugin tests in my develop branch. It looks good.

I didn't have another event issue at the moment.

FYI, when I get some time I plan on having the opentelemetry plugin live in opentelemetry-dotnet-contrib. The metrics part of the OTel plugin was easy to produce. But I was wondering if I could hook "tracing" better. Maybe just adding a tag to an existing Activity so that things like HttpClient and/or EF traces would have a tag indicating it was FusionCache as the caller. Just need to find some time. Being in the contrib project would probably give FusionCache even more exposure.

jodydonetti commented 2 years ago

I checked the Main branch against the Metrics Plugin tests in my develop branch. It looks good.

I didn't have another event issue at the moment.

That's great 🎉

FYI, when I get some time I plan on having the opentelemetry plugin live in opentelemetry-dotnet-contrib. The metrics part of the OTel plugin was easy to produce. But I was wondering if I could hook "tracing" better. Maybe just adding a tag to an existing Activity so that things like HttpClient and/or EF traces would have a tag indicating it was FusionCache as the caller. Just need to find some time. Being in the contrib project would probably give FusionCache even more exposure.

Wow, that is awesome @JoeShook and it would be great if it will be included there!

jodydonetti commented 2 years ago

Hi @JoeShook , I just released v0.11.0 which includes the fix for this issue 🎉

Hope this helps.