Skip to content

feat: New IFeatureFlagCache interface and implementations #12

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

Merged
merged 4 commits into from
Jan 17, 2025

Conversation

haacked
Copy link
Collaborator

@haacked haacked commented Jan 17, 2025

The HttpContextFeatureFlagCache implements IFeatureFlagCache and retrieves feature flags from HttpContext.Items if they exist. Otherwise it calls the /decide endpoint. Items are cached per distinctUserId, which in most cases will map 1-1 to an HTTP request.

If the HttpContext is not available, then feature flags are always requested.

By default, PostHogClient will use a NullFeatureFlagCache with no caching. When registering PostHogClient using the methods provided for ASP.NET Core, that's replaced with an HttpContextFeatureFlagCache.

Fixes #11

Also implement this twice, a default implementation and an implementation that caches in HttpContext.Items.
When using the `PostHogClient` in the context of an aspnetcore request, feature flags are retrieved once per HTTP request and cached for the duration of that request.

Under the hood, this is implemented by storing them in `HttpContext.Items`.

Fixes #11
Something that's unlikely to create a conflict.
@haacked haacked merged commit f577917 into main Jan 17, 2025
2 checks passed
@haacked haacked deleted the haacked/11-http-request-caching branch January 17, 2025 04:44
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

Successfully merging this pull request may close these issues.

Cache Decide Requests per HTTP request
1 participant