Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add caching logic to Growthbook repositories #114

Merged
merged 6 commits into from
Jan 31, 2025

Conversation

vazarkevych
Copy link
Collaborator

Add caching logic to Growthbook repositories to improve performance and enable the ability to retrieve feature JSON data from the cache.

Volodymyr Nazarkevych added 6 commits January 23, 2025 22:41
…hing-enable

# Conflicts:
#	lib/src/main/java/growthbook/sdk/java/GBFeaturesRepository.java
#	lib/src/main/java/growthbook/sdk/java/NativeJavaGbFeatureRepository.java
#	lib/src/main/java/growthbook/sdk/java/multiusermode/GrowthBookClient.java
#	lib/src/test/java/growthbook/sdk/java/GBFeaturesRepositoryRefreshingTest.java
#	lib/src/test/java/growthbook/sdk/java/GBFeaturesRepositoryTest.java
#	lib/src/test/java/growthbook/sdk/java/multiusermode/GrowthBookClientTest.java
@vazarkevych vazarkevych merged commit e675af6 into release/0.9.92 Jan 31, 2025
1 check passed
@vazarkevych vazarkevych deleted the feature/caching-enable branch January 31, 2025 12:36
vazarkevych added a commit that referenced this pull request Feb 3, 2025
* SDK version was updated

* LocalGbFeatureRepository (#101)

* LocalGbFeatureRepository was added

* Code cleanup

* Error fix

---------

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* IGBFeaturesRepository implementation based on java.net.HttpURLConnection (#100)

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* Constants interface was removed

* Docs were updated (#103)

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* Changes from comment

* Changes to enable Multi Context Support (#106)

* changes for multi context sdk

* remove debug statements

* handle empty attributes for force

* remove debug statements

* fix javadoc comments

* support attributes as a string

* add GrowthBookMultiUser details

* remove debug statements

* add feature refresh callbacks

* remove debug statements

* fix incorrect example value in README.md

* remove obsolete files

* deprecate encKey

* deprecate encKey

* Use global context at instance level

* LRU cache for tracking experiments

* Changes from comment

* reset stackContext for eval in old instance

* rename GNMultiUser to GBClient

* add unit tests

* fix parent cond evaluation

* changes for multi context sdk

* remove debug statements

* handle empty attributes for force

* remove debug statements

* fix javadoc comments

* support attributes as a string

* add GrowthBookMultiUser details

* remove debug statements

* add feature refresh callbacks

* remove debug statements

* fix incorrect example value in README.md

* remove obsolete files

* deprecate encKey

* deprecate encKey

* Use global context at instance level

* LRU cache for tracking experiments

* reset stackContext for eval in old instance

* rename GNMultiUser to GBClient

* add unit tests

* fix parent cond evaluation

---------

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* fix trackdata in evaluation process, add remote eval feature, fix tests add test for LocalGbFeatureRepository and NativeJavaGbFeatureRepository; add ability to pass requestBody for madhu variant of GBClient; fix test, add remote eval feature to new flow of initialize GB

* fix logic of subscriptions; add subscriptions to GBClient; (#113)

add experiment parameter to callback

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* update guava dependency (#111)

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* fix logic of subscriptions; add subscriptions to GBClient; add experiment parameter to callback

* Manual forced feature  (#108)

* add ability to evaluate manual force feature

* fix logic of subscriptions; add subscriptions to GBClient;
add experiment parameter to callback

* initialize dependencies through constructors in main classes, remove getter and setter for forcedFeatureValues in GBClient, fix test

* add setter and getter for attributeOverrides, make assigned experiments final, fix initialising savedGroups and attributeOverrides through setter and constructors

---------

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* remove FeatureEvalContext.java, remove from AssignedExperiment objects of experiment and result, replace them with key, inExperiment variable and variationId, fix fireSubscriptions function

* replace map as request body with specific Payload class and configure this payload object with data from Options, fix logic of getting forceVariation and forceFeatureValues from global context and user context, fix test

* make fetchFeatures and fetchForRemoteEval public to  be able to refresh features, remove Payload field from GrowthBookClient, rename payload to RequestBodyForRemoteEval, add setters for global: attributes, forceFeatures, forceVariations, add refresh functions, fix test and reorganize code

* add tests for remote eval

* Improvements for Remote Evaluation  (#109)

* fix trackdata in evaluation process, add remote eval feature, fix tests add test for LocalGbFeatureRepository and NativeJavaGbFeatureRepository; add ability to pass requestBody for madhu variant of GBClient; fix test, add remote eval feature to new flow of initialize GB

* fix logic of subscriptions; add subscriptions to GBClient; add experiment parameter to callback

* remove FeatureEvalContext.java, remove from AssignedExperiment objects of experiment and result, replace them with key, inExperiment variable and variationId, fix fireSubscriptions function

* replace map as request body with specific Payload class and configure this payload object with data from Options, fix logic of getting forceVariation and forceFeatureValues from global context and user context, fix test

* make fetchFeatures and fetchForRemoteEval public to  be able to refresh features, remove Payload field from GrowthBookClient, rename payload to RequestBodyForRemoteEval, add setters for global: attributes, forceFeatures, forceVariations, add refresh functions, fix test and reorganize code

---------

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>
Co-authored-by: Volodymyr Nazarkevych <volodymyr.nazarkevych@kevychsoulutions.com>
Co-authored-by: Volodymyr Nazarkevych <volodymyr.nazarkevych@kevychsoulutions.com>

* pass  requestBodyForRemoteEval to refreshForRemoteEval function, update README.md

* fix Readme explanation for functions

* fix import

* Add caching logic to Growthbook repositories (#114)

* Add caching logic to GBFeaturesRepository and NativeJavaGbFeatureRepository

* Add test for CachingManager and add caching logic for GBFeaturesRepository

* improve caching in NativeJavaGbFeatureRepository to reduce double fetching from cache

* fix code

* fix conflicts after merge release 0.9.92 to feature/caching enable branch

---------

Co-authored-by: Volodymyr Nazarkevych <volodymyr.nazarkevych@kevychsoulutions.com>

* fix tests

* comment shouldHandleLargeContent test

* comment shouldThrowExceptionWhenReadingFails test

* Fix evaluating force property in rule when rule is JsonObject and defined as null (#112)

* fix evaluating force property in rule when rule is JsonObject and defined as null

* replace hasForceProperty logic with wrapper to distinguish if force field is present in response or not

---------

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>

* Throw exception on HTTP errors (#115)

* Throw exception on HTTP errors

Adds a new FeatureFetchErrorCode called HTTP_RESPONSE_ERROR that is used on non-200 HTTP status codes and also logs the server response.

One of the common instances this happens is when you use a wrong SDK key.

They were previously mangled into FeatureFetchErrorCode.CONFIGURATION_ERROR with a very non-descriptive message of "No features found".

* Fix conflicts after adding caching logic, update mergeMaps function, add a new constructor to GBFeaturesRepository, and refine onSuccess logic based on client feedback.

---------

Co-authored-by: Volodymyr Nazarkevych <volodymyr.nazarkevych@kevychsoulutions.com>

---------

Co-authored-by: Bohdan Akimenko <bohdan.akimenko@kevychsolutions.com>
Co-authored-by: Madhu Chavva <46016208+madhuchavva@users.noreply.github.com>
Co-authored-by: Volodymyr Nazarkevych <mykyta.salohub@kevychsolutions.com>
Co-authored-by: Volodymyr Nazarkevych <volodymyr.nazarkevych@kevychsoulutions.com>
Co-authored-by: Martin Thurau <martin.thurau@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant