Advanced caching scenario #235
-
Hello, I wrote some caching scenario and I would like to verify, if I am correct. We are using one instance of a web application (=> no backplane needed - is that correct?). Now with the following settings I expect following scenario (correct me if I am wrong).
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi @suchoss , and thanks for using FusionCache!
Correct! The backplane is useful in multi-node scenarios.
This code seems technically correct, below I'll try to explain more each option.
Correct.
Correct.
Correct, IF the data is in L2 (Redis may have restarted or else), and IF the communication with L2 takes less than So, in the "easy scenario" (without considering shifted updates from different nodes, Redis restarts, etc), L1 will be updated every Makes sense?
Not exactly: at every call FusionCache tries with L1 and, if no fresh data is there it tries with L2, and if not fresh data is there (or if talking with L2 took more than the configured If then the factory fails (eg: the database is down or similar), then fail-safe kicks in and temporarily re-use the stale value, by saving it again in the cache for some time ( After Makes sense?
Not exactly: Having said that, when calling L2 after
See above.
This is always the case: if a factory is executed completely in the background (eg: Eager Refresh) or if it starts normally but is then is moved to finish execution in the background (eg: soft/hard timeouts), as soon as it finishes it will automatically update "the cache", meaning both L1 and L2 (if configured).
Think about it this way: in general a "soft timeout" is used when there IS a stale value to use as a fallback, and a "hard timeout" is used when there IS NOT one. This is in general a way for you to say to FusionCache "if you have something stale to use, you can return that faster and finish inthe background, no big deal, but if you don't have something stale to return you can wait a little bit longer (or indefinitely)". Timeouts then exist for both when executing the factory ( So, getting back to your question of "What does FactorySoftTimeout do here?" the answer is that it is the maximum time to wait for a factory execution to finish, IF fail-safe is enabled and IF there is a stale value to fall back to: if it takes longer than that, the stale value will be temporarily re-used and the factory will end execution in the background, automatically updating the cache right after finishing execution. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Hi @jodydonetti Thanks for your exhausting answers. It brought some clarification 😄. BTW I was thinking about the documentation. Flowcharts and sequence diagrams might be a way to go (I like the documentation here https://www.pollydocs.org/strategies/retry.html). I will try to draw something and let you know. ps: I said hi to Michal 🤣 |
Beta Was this translation helpful? Give feedback.
I'm thinking about a different ways to spin the docs, maybe a different approach for somebody new to FusionCache.
Will update if I come up with something.
Good question: apart from the backplane, everything in FusionCahe is "lazy", meaning it only does something when asked for.
Concrete example: your Redis cache …