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 · 1 comment
Open
1 task done

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

Grendel7 opened this issue Oct 2, 2024 · 1 comment
Assignees
Labels
maybe later Something we may choose to do at a later date but not now

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.

@sighphyre sighphyre added the maybe later Something we may choose to do at a later date but not now label Nov 27, 2024
@sighphyre
Copy link
Member

Hey @Grendel7, while the situation isn't ideal at the moment I think you're doing the right thing with what you've done. This is something I think we may want to improve at a future date but I don't think we'll do anything soon

@sighphyre sighphyre moved this from Investigating to For later in Issues and PRs Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maybe later Something we may choose to do at a later date but not now
Projects
Status: For later
Development

No branches or pull requests

3 participants