flipper icon indicating copy to clipboard operation
flipper copied to clipboard

Introduce Flipper::Adapters::FallbackToCached

Open jonmagic opened this issue 1 year ago • 3 comments
trafficstars

Why?

For my use case I need to be able to cache values each time features, get, get_multi, or get_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 of features, get, get_multi, and get_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.

jonmagic avatar Apr 08 '24 20:04 jonmagic

I think my only issue with this is the inheriting from memorizable and turning memoize off.

It might be just because I haven't started from scratch on it to see how much is shared.

I think I'll take a stab at it from scratch to see the difference.

jnunemaker avatar Apr 14 '24 14:04 jnunemaker

turning memoize off.

I think you have to turn this off or it will add the memoizable adapter as the first in the stack and it defeats the purpose of this change.

jonmagic avatar Apr 15 '24 16:04 jonmagic

Memoizable usually just sits in front and falls back to the original adapter. So if your original falls back to in memory cache it should just work. Maybe something else weird was at play. I'll have to kick the tires.

jnunemaker avatar Apr 17 '24 14:04 jnunemaker