ZiggyCreatures / FusionCache

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

[BUG] Type cannot be inferred from GetOrSetAsync #144

Closed celluj34 closed 1 year ago

celluj34 commented 1 year ago

Describe the bug Since updating to 0.21, types cannot be inferred from GetOrSetAsync.

To Reproduce

var date = _cache.GetOrSetAsync("my date",
    async (context, token) =>
    {
        return DateTime.Now;
    });

Expected behavior I expect the types to be inferred from the return type of the factory.

Versions I've encountered this issue on:

Screenshots image

Additional context You can work around the issue by providing the type explicitly in the method call, like so:

var date = _cache.GetOrSetAsync<DateTime>("my date",
    async (context, token) =>
    {
        return DateTime.Now;
    });
jodydonetti commented 1 year ago

Hi @celluj34 , yep it was in the release notes

image

Sadly there's nothing I can do, it seems to be a limitation of the current version of the compiler.

celluj34 commented 1 year ago

Ah, I see. Sorry I did not read thoroughly enough, I was too excited to start using the conditional refresh feature! Thank you for setting me straight!

jodydonetti commented 1 year ago

I was too excited to start using the conditional refresh feature!

I'm you were expecting it so much, if you like let me know how it went 😁

celluj34 commented 1 year ago

Honestly it's so much nicer than what I had to do before. The previous flow was complicated and we had to store 3 values for each set of data. We wanted to keep our data for 1 hour, but check at a maximum of every 10 minutes for staleness.

The way you've built the new methods with the existing FailSafe logic is just perfect for our use case.

jodydonetti commented 1 year ago

Hi @celluj34 , what can I say? Thanks for your words, they made my day 😊

I'm glad it ended up working well and that you are liking the way I designed it, it means a lot!