Introduce Flipper::Adapters::FallbackToCached #860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
For my use case I need to be able to cache values each time
features
,get
,get_multi
, orget_all
are called but only use those cached values if subsequent calls to them fail. It should raise an error if no cached values are there to use.How?
I introduced a new adapter called
Flipper::Adapters::FallbackToCached
that inherits from the Memoizable adapter and wraps another adapter. It updates the implementation offeatures
,get
,get_multi
, andget_all
to call the primary adapter and caches the values. If the primary adapter raises an error, it will return the cached value instead. If there is no cached value, it will raise the error.Please note you have to disable memoize when configuring Flipper so that it doesn't use the Memoizable adapter like it normally would.