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

keeping stale values in case the backend is offline #385

Closed
barkanido opened this issue Jan 12, 2020 · 8 comments
Closed

keeping stale values in case the backend is offline #385

barkanido opened this issue Jan 12, 2020 · 8 comments

Comments

@barkanido
Copy link

Hey,
First, thanks for this great library.
I would like to configure Caffeine to save stale values in case the backend is off. This means if you cache a DB query and the DB query, and the DB goes offline for some reason. The cache would preserve the same values even after they are considered stale. This is because, in a few use cases, a stale value is better than no value.
This is doable with refreshAfterWrite but this API is not as flexible as expireAfter. This might be a duplicate of #360 but I wonder if there is another way (even if less straightforward) of doing so.

@ben-manes
Copy link
Owner

Perhaps a victim cache would work? In that case when the writer synchronously evicts, you capture it into a secondary cache. A subsequent loader call could fetch it, resurrecting the entry. That might provide the lifecycle hack that you’re looking for.

@barkanido
Copy link
Author

in that case when the writer synchronously evicts...

which writer? do you mean an external thread that invalidates the cache?

@ben-manes
Copy link
Owner

I meant if you supply a CacheWriter.

@barkanido
Copy link
Author

do you mean a configuration like your comment here?

@ben-manes
Copy link
Owner

Yes, something like that might work?

@barkanido
Copy link
Author

I think it might work. thanks!

@VytautasSer
Copy link

VytautasSer commented Mar 30, 2020

Hello,

Have you found a solution to this problem? Could you share it? Sad that there is no such thing out of the box.

@barkanido
Copy link
Author

Look in the example above by @ben-manes . also, note that with a loadingCache, a backend failure will throw an exception and the mapping is unchanged so you get the old value by default (if it was there already)

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

No branches or pull requests

3 participants