feat(flags): Add ETag support for local evaluation caching#91
Merged
feat(flags): Add ETag support for local evaluation caching#91
Conversation
Add HTTP ETag caching for feature flag definitions to reduce bandwidth when polling for flag updates. When flags haven't changed, the server returns 304 Not Modified and cached flags are preserved.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements HTTP ETag-based caching for feature flag definitions in the PostHog PHP library, reducing bandwidth consumption during flag polling. When flags haven't changed, the server returns a 304 Not Modified response, allowing the client to reuse cached flag data instead of re-transmitting the full payload.
Key Changes
- Added ETag extraction and storage from HTTP responses with If-None-Match header support for conditional requests
- Enhanced HttpResponse class to include ETag metadata and 304 status detection
- Updated MockedHttpClient test infrastructure to support ETag scenarios and response queuing
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/HttpResponse.php | Added ETag property, getter method, and isNotModified() helper for 304 detection |
| lib/HttpClient.php | Implemented ETag extraction from response headers, 304 status handling, and token masking utility |
| lib/Client.php | Added ETag caching state, If-None-Match header injection, and 304 response handling in loadFlags() |
| lib/PostHog.php | Added getClient() method to expose Client instance for accessing ETag functionality |
| test/EtagSupportTest.php | Comprehensive test suite covering ETag storage, If-None-Match headers, 304 handling, and edge cases |
| test/HttpClientTest.php | New tests for token masking functionality in URLs |
| test/MockedHttpClient.php | Enhanced mock to support ETag responses and sequential response queuing for testing |
| test/PostHogTest.php | Updated test expectations to include includeEtag request option |
| test/FeatureFlagTest.php | Updated test expectations to include includeEtag request option |
| test/FeatureFlagLocalEvaluationTest.php | Updated test expectations to include includeEtag request option |
| example.php | Added interactive ETag polling example demonstrating bandwidth optimization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dustinbyrne
approved these changes
Dec 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add HTTP ETag caching for feature flag definitions to reduce bandwidth when polling for flag updates. When flags haven't changed, the server returns 304 Not Modified and cached flags are preserved.
Based on the work we did for PostHog/posthog-js#2678