ZiggyCreatures / FusionCache

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

[FEATURE] Combination of eager refresh with distributed cache duration. #205

Closed sudo-ds closed 5 months ago

sudo-ds commented 6 months ago

Problem

I wanted to use a combination of an eager refresh with a duration of distributed cache layer (DistributedCacheDuration). If I'm correct by default eager refresh works with Duration of first in memory cache layer and most of the users are using the same duration for both layers. I wanted to use different durations for each layer + eager refresh for the duration of the second layer.

Motivation

The reason for combining different durations for each layer + eager refresh is mostly meant to be as workaround in situations like some node will update distributed cache and we don't have a backplane.

jodydonetti commented 6 months ago

Hi @sudo-ds and thanks for using FusionCache!

I'm trying to better understand your scenario, so let's make an example: you want to cache in memory for 10sec, in distributed for 10min, but also want to eager refresh at, say, 8min (80% of distributed duration)?

Is this it?

sudo-ds commented 6 months ago

Hi @sudo-ds and thanks for using FusionCache!

I'm trying to better understand your scenario, so let's make an example: you want to cache in memory for 10sec, in distributed for 10min, but also want to eager refresh at, say, 8min (80% of distributed duration)?

Is this it?

Yes exactly.

jodydonetti commented 6 months ago

In this specific case what I would suggest is to set the DistributedCacheDuration to the early value (8min in the previous example) and enable fail-safe + soft timeout: in this way the refresh will happen earlier, and you'll be protected from both transient failures during refresh, and also slow refresh, basically getting the same result.

Hope this helps.

jodydonetti commented 6 months ago

Hi @sudo-ds , did it work?

jodydonetti commented 5 months ago

Hi @sudo-ds , any news about this? I'm closing this for now but let me know and I'll reopen it.