-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Take into account failSafeDefaultValue for factory timeout #67
Conversation
Hi @alexmaek and thanks for using FusionCache! Sorry for the delay in answering but covid finally got me so, yeah 🤷 Anyway, let me tell you: honestly, good catch! When laid out like you did it makes total sense, and it feels so strange not to have thought about it before but yeah, I agree that Let me reason about this a little bit more, to see if that can also impact somewhere else in the code, and I will get back to you asap. Thanks! |
Ok, I took some time and everything seems to make sense! I'm merging this and will release a new version soon along with some other minor things I'm finishing. Good catch and thanks again! |
That's great, thanks to you for building this great library! I'll keep my eyes peeled for the next release. |
Hi @alexmaek , now that I've released the new version with the fix I happened to stumble upon a certain case which I would like to discuss with you. My scenarioIn one of the apps where I'm using FusionCache I've found a The thing that surprised me was that in places where usually I got back some data in the first So, I would like the Next stepsNow, before changing it back immediately to the previous behaviour or start adding new options to configure how the What do you think? |
Hi @jodydonetti I intended to take a look at this with a work colleague during the week, but we've been having quite a rough one. We'll try to get to it the following one, but don't hesitate to take the decision you think best if you need to fix this quickly. |
Hi @alexmaek , thanks for the update. I agree with you and so, to avoid unwanted surprises for existing users, I've quickly released v0.11.1 that (temporarily?) rollback the change introduced in v0.11.0. When you and your colleague will have some time I'd like to discuss this a bit more, since as I've said the change was absolutely reasonable, but I think there should be a way to better control it or anyway a better heuristic for when to use it. Take your time and thanks again. |
Hi @jodydonetti I've talked with my colleagues but couldn't find a catchall solution. We'll keep investigating alternative ways to make this work. For now we've devised the following: We're using the soft timeout in order to end the cache query quickly, but continue executing the factory in background. In order to emulate this behavior, we could use a hard timeout to interrupt the cache query (and the factory call) and afterwards relaunch the factory manually in background, saving its result to cache once its finished. It's not the greatest solution: the factory is called twice and interrupted once and some of these changes may negatively impact code readability. But for now it's all we could come up without proposing any deep internal changes to FusionCache. As I said, we'll keep thinking it over, let's hope we come up with some other ideas. I'll get back to this thread in a few days. |
Hi @alexmaek , one quick thing I haven't thought of before, and it's very simple: why not just set both the soft + hard timeouts (to the same value) and provide a I mean, let's say you set both of them to Wouldn't this cover every use case?
You should not need to do this manually, it should already work like this in the way I described above: just set both soft and hard timeouts and specify a Please give it a try and let me know. |
To be more explicit: it would be like saying "hey FusionCache, whether you have a stale value to use as a fallback or not, stop waiting after Does this make sense? |
Well, that's exactly what we need. I've wrongly assumed that the hard timeout would interrupt the factory. I've tested it and works like you described. I'll share the news with my colleague, but we can probably solve our use case this way. If that's the case then I can only offer my apologies for this whole confusion 😅 |
Nope, both would keep the factory running in the background or not, based on the Now that we are talking about this I'm thinking about making it more clear in the docs where it says:
Maybe I can add a more explicit note or an example, will think about that.
Awesome! In case that is not the case let me know and we'll work something out.
Ahah no worries, and actually I'm sorry it took me this long to get your scenario: I'm the one who created FusionCache, so I should've suggested this solution way before. |
Hi Jody!
We started using FusionCache at my company and encountered a strange case when dealing with factory tiemouts and failsafe values.
What happens is that when doing a
GetOrSetAsync
call specifying a factory and its soft timeout and a failsafe value, I expected the factory to terminate after the soft timeout expires and for the call to return the default failsafe value, but it keeps running until finished. This prevents being able to run a fail-fast scenario in first time cache calls.I've prepared a PoC based on the scenarios on
ZiggyCreatures.FusionCache.Playground
, this is the simplest case I could came up with, no distributed cache, only in memory and no other options:When running this code you'll get a message saying
or some similar time value, even though
.SetFactoryTimeouts(TimeSpan.FromMilliseconds(100))
was specified.Diving into the library's code if narrowed down the tiemout selection to this call:
var timeout = options.GetAppropriateFactoryTimeout(memoryEntry is object || distributedEntry is object);
. I understand that the factory soft timeout is only set up when there's a "normal" failsafe value, one that was returned correctly in a previous call. But it doesn't take into account a possiblefailSafeDefaultValue
.In this pull request proposal I've added the check to take into account the
failSafeDefaultValue
, but would like to get your input on this in case I'm missing something.