Skip to content
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

[cache-manager] Add an option to update all layers/stores on refresh #916

Closed
meteorlxy opened this issue Dec 3, 2024 · 1 comment · Fixed by #917
Closed

[cache-manager] Add an option to update all layers/stores on refresh #916

meteorlxy opened this issue Dec 3, 2024 · 1 comment · Fixed by #917

Comments

@meteorlxy
Copy link
Contributor

Is your feature request related to a problem? Please describe.

For example, there is a 2-layer cache:

Layer 1 -> ttl=1d
Layer 2 -> ttl=2d

Both of them have refreshThreshold=1h

After 23h, the Layer 1 will refresh according to refreshThreshold.

However, per the current implementation, only stores.slice(0, i + 1) (only Layer 1 in this case) will be updated, while the Layer 2 still have stale data:

if (shouldRefresh) {
coalesceAsync(`+++${key}`, fnc)
.then(async result => {
try {
await set(stores.slice(0, i + 1), key, result, ms);
eventEmitter.emit('refresh', {key, value: result});
} catch (error) {
eventEmitter.emit('refresh', {key, value, error});
}
})

If the Layer 1 somehow crashed between 1d and 2d, the cache will fallback to Layer 2 with stale data, which is not ideal.

Describe the solution you'd like

Provide a new option like refreshAllStores to update all layers on refresh.

@jaredwray
Copy link
Owner

@meteorlxy - We will get this merged and published in the next 5-7 days! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants