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

Feat: Store features in memory after loading them from cache #230

Open
1 task done
Grendel7 opened this issue Oct 2, 2024 · 0 comments
Open
1 task done

Feat: Store features in memory after loading them from cache #230

Grendel7 opened this issue Oct 2, 2024 · 0 comments
Assignees

Comments

@Grendel7
Copy link

Grendel7 commented Oct 2, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the new feature

When the Unleash client is called multiple times within a request, it should load the features once (whether from the Unleash server or from cache) and reuse it for the duration of the request, to prevent unnecessary network calls.

Is your feature request related to a problem? (optional)

Right now, any time Unleash::isEnabled is called, it calls DefaultUnleashRepository::getFeatures. This function then loads the full feature set from cache to be able to tell whether this particular feature is enabled.

In my application, some requests have Unleash calls peppered across them to add certain changes to certain parts of the page, and each of these calls loads the data from cache.

I'm using Laravel with a Redis cache. While Redis is fast, it's still a network call, so it's not free. And dozens of extra calls to Redis to obtain the same information repeatedly for every request generates noticeable performance overhead.

Describe alternatives you've considered (optional)

I have considered extending the functionality of certain classes to add the memoization myself, but:

  • Since virtually every class is final, I'd have to copy-paste substantial parts of some classes myself.
  • I had a hard time figuring out how to just replace the UnleashRepository implementation, UnleashBuilder doesn't appear to have this option as far as I can tell.
  • I think that this would make sense to have this in the client by default, it's not an issue specific to my use case.

My current workaround is to implement and use a special tiered cache store that stores the values in memory as well as in Redis. But that's just hacking around the limitation using the controls available.

Additional context (optional)

The naive approach would be to just load the features into memory and reuse them as long as they are available. However, this would cause problems for long running requests, like background workers or using servers like FrankenPHP, so some checks for freshness of the in-memory data would be helpful.

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

No branches or pull requests

2 participants